PROJEKTY NUMERKI rozniczka


function[x,f,df,d2f,h]=tabela_funkcji(a,b,n)
h=(b-a)/n;
for i=1:n+1;
x(i)=a+(i-1)*h;
[f(i),df(i),d2f(i)]=fun(x(i));
end
endfunction

function[f,df,d2f]=fun(x)
f=x.^2+x-1;
df=2*x+1;
d2f=2;
endfunction

function[df,d2f]=pierwsza_druga_pochodna(h,f,n)
h2=1/(2*h)
h22=1/(h*h)
df(1)=h2*(-3*f(1)+4*f(2)-f(3));
d2f(1)=h22*(f(1)-2*f(2)+f(3));
for i=2:n
df(i)=h2*(-f(i-1)+f(i+1));
d2f(i)=h22*(f(i-1)-2*f(i)+f(i+1));
end
df(n+1)=h2*(f(n-1)-4*f(n)+3*f(n+1));
d2f(n+1)=h22*(f(n-1)-2*f(n)+f(n+1));
endfunction

%%%dane%%%%
a=0, b=12, n=4,
[x,f,df,d2f,h]=tabela_funkcji(a,b,n)
[df,d2f]=pierwsza_druga_pochodna(h,f,n)

ROZNICZKOWANIE PIERWSZA POCHODNA


#! /usr/bin/octave -q

%funkcje
function[x,f,df,h]=tab(a,b,n)
x=zeros(1,n+1);
f=zeros(1,n+1);
df=zeros(1,n+1);

h=(b-a)/n;


for i=1:n+1
x(i)=a+(i-1)*h;
[f(i),df(i)]=fun(x(i));
end %for

end %function


function[f,df]=fun(x)
f=2*x*x+x+cos(x*x);
df=4*x+1-sin(x*x)*2*x;
end %function



function[dy]=poch(h,f,n)

dy=zeros(1,n+1);

h2=1/(2*h)
dy(1)=h2*(-3*f(1)+4*f(2)-f(3));

for i=2:n
dy(i)=h2*(-f(i-1)+f(i+1));
end %for

dy(n+1)=h2*(f(n-1)-4*f(n)+3*f(n+1));
end %function




%dane
a=0, b=35, n=7,


%wywolanie
[x,f,df,h]=tab(a,b,n)
[dy]=poch(h,f,n)

%wykres
hold on;
plot(x,f)
hold on;
plot(x,df)
hold on;
plot(x,dy)
pause()

Wyszukiwarka