//całkowanie metodą trapezów w matlabie
clc
clear all
n=input('podaj liczbe przedzialów n=');
h=input('podaj szerokosc przedzialów h=');
for i=1
n+1)
tmp=['y(',int2str(i),')= '];
y(i)=input(tmp);
end
J1=(h/2)*(y(1)+y(n+1));
J2=0;
for i=2:n
J2=J2+h*y(i);
end
J=J1+J2;
tmp=['calka wynosi J=' ,num2str(J)];
disp(tmp);
--------------------------------------------
x=input ('podaj wartosc zmiennej x:');
if x >3
f=x.^4-x.*x-6;
elseif x >=-1 & x<=3
f=sin(x);
else
f=x.*x-2;
end
f
----------------------------------------
a=0; b=3;
blad=eps*b
fa=-inf;
fb=inf;
fx=inf
while ((b-a)>=blad)
x=(a+b)/2;
fx=x.^3-2*x-5;
if (fx==0)
break;
elseif sign(fx)==sign(fa);
a=x
fa=fx
else
b=x
fb=fx
end
end
x
x=[0:0.01:3];fx=x.^3-2.*x-5;
plot (x,fx);grid on
----------------------------------------------------
clc
clear all
n=input('podaj liczba punktow pomiarowych n=')
x0=input('podaj x pierwszego punktu pomiarowego x=');
h=input('podaj dlugosc przedzialu h=');
for i=1
n+1)
tmp=['y(',int2str(i),')='];
y(i)=input (tmp);
end
for i=1
n-1)
x(i)=x0+h*(i-1);
end
x
J1=h/2*y(i)+y(n-1);
J2=0;
for i=2:n
J2=J2+h*y(i);
end
J=J1+J2;
tmp['wartosc calki wynosi',num2srt(J)];
disp(tmp);
end
--------------------------------------------------------
bisek.\clear;
a=0;
b=3;
dokl=(b-a)<eps*b;
f(a);
f(b);
f(x);
while((b-a)>dokl)
{
x=(a+b)/2;
f(x)=x.^3-2*x-5;
}
if f(x)==0; break;
elseif
sign(f(x))=sign(f(a));
x=a;
f(x)=f(a);
else
b=x;
f(b)=f(x);
------------------
function choinka
hold on
x=[5 7 7 5 5]
y=[2 2 4 4 2]
plot(x,y)
x=[9 6 5]
y=[4 6 4]
x=[8 6 4]
y=[6 8 6]
x=[9 6 5]
y=[4 6 4]
plot(x,y)
------------------
sieczne
clear all;
blad=0.0001;
i=0 ;
x1(1)=0 ;
x=x1(1) ;
y1(1)=(2*x1(1))-(2*sin(x1(1)))-1;
y=y1(1);
fprintf('iteracja:0\n\n')
fprintf('x=%d y=%.3f\n\n',x,y)
i=1;
x1(2)=2;
x=x1(2);
y1(2)=(2*x1(2))-(2*sin(x1(2)))-1;
y=y1(2);
fprintf('iteracja:1\n\n')
fprintf('x=%d y=%.3f\n\n',x,y)
xa=0:0.01:3;
ya=2*xa-2*sin(xa)-1;
plot(xa,ya,'m'); grid on
hold on;
for i=2:30
x1(i+1)=x1(i)-((y1(i)*(x1(i)-x1(i-1)))/(y1(i)-y1(i-1)));
y1(i+1)=2*x1(i+1)-2*sin(x1(i+1))-1;
x=x1(i+1);
y=y1(i+1);
fprintf('iteracja:%d\n\n',i)
fprintf('x=%.4f y=%.5f\n\n',x,y)
a=x1(i-1);
b=x1(i);
xb=[a;b];
c=y1(i-1);
d=y1(i);
yb=[c;d];
line(xb,yb); grid on
hold on;
if abs(y1(i+1))< blad
plot(x,y,'bx');
break;
end
end
---------------------------
sieczne2
clear all;
close all;
blad=0.0001;
fprintf('Obliczenia pierwiastka rownania w(-0.5,0)')
i=0;
x1(1)=-0.5 ;
x=x1(1);
y1(1)=log(x1(1)^(2))+4;
y=y1(1);
fprintf('iteracja:%d\n\n',i)
fprintf('x=%.1f y=%.5f\n\n ',x,y);
i=1;
x1(2)=-0.001;
x=x1(2);
y1(2)=log(x1(2)^2)+4;
y=y1(2);
fprintf('iteracja:%d\n\n',i)
fprintf('x=%.3f y=%.5f\n\n ',x,y);
xa=-1:0.01:1;
ya=log(xa.^(2))+4;
plot(xa,ya,'red'); grid on
hold on;
for i=2:30
x1(i+1)=x1(i)-((y1(i)*(x1(i)-x1(i-1)))/(y1(i)-y1(i-1)));
y1(i+1)=log(x1(i+1)^2)+4;
if abs(y1(i+1))< blad
plot(x,y,'bx')
break;
end;
x=x1(i+1);
y=y1(i+1);
fprintf('iteracja:%d \n\n',i)
fprintf('x=%.4f y=%.5f\n\n',x,y)
a=x1(i-1);
b=x1(i);
xb=[a;b];
c=y1(i-1);
d=y1(i);
yb=[c;d];
line(xb,yb); grid on
hold on;
end
fprintf('Obliczenia nastepnego pierwiastka w (0,0.5)')
i=0;
x1(1)=0.5 ;
x=x1(1);
y1(1)=log(x1(1)^(2))+4;
y=y1(1);
fprintf('iteracja:%d\n\n',i)
fprintf('x=%.3f y=%.5f\n\n ',x,y);
i=1;
x1(2)=0.001;
x=x1(2);
y1(2)=log(x1(2)^2)+4;
y=y1(2);
fprintf('iteracja:%d\n\n',i)
fprintf('x=%.1f y=%.5f\n\n ',x,y);
for i=2:30
x1(i+1)=x1(i)-((y1(i)*(x1(i)-x1(i-1)))/(y1(i)-y1(i-1)));
y1(i+1)=log(x1(i+1)^2)+4;
if abs(y1(i+1))< blad
plot(x,y,'bx')
break;
end;
x=x1(i+1);
y=y1(i+1);
fprintf('iteracja:%d \n\n',i)
fprintf('x=%.4f y=%.5f\n\n',x,y)
a=x1(i-1);
b=x1(i);
xb=[a;b];
c=y1(i-1);
d=y1(i);
yb=[c;d];
line(xb,yb); grid on
hold on;
end
---------------------------------------------