Matematica
1)
function y=f(x)
y=sin(x)-2*cos(x)+x^2-((3.14^2)-2);
function y =df(f,x)
e=0.00001;
y=(feval(f,x+e)-feval(f,x-e))/(2*e);
>>x=0
x=
0
>>f(x)
ans= -9.8696
>>df(@f,x)
ans=
1
2)
function y=f(x)
y=sin(x)-2*cos(2x)+x^2-((pi^2)-2);
function y=f1(x)
y=cos(x)+4*sin(x)+2*x;
function y=newt(f,f1,x)
x1=x;
error=1;emin=0.00001;
while error>emin
x2=x1-(feval(f,x1)/feval(f1,x1));
error=abs(x2-x1);
x1=x2;
end
y=x1;
x=pi
x =
3.1416
>> f(x)
ans =
-9.8996
>> g1(x)ans =
1
>> newt(@f,@f1,x)
ans =
3.1308
3)
function y=f(x)
y=sin(x)-2*cos(2x)+x^2-((pi^2)-2);
function y=raiz(f,x)
x1=x;
e=0.0001;
error=1;
emin=0.00001;
whileerror>emin
x2=x1-(feval(f,x1)*e*2/(feval(f,x+e)-feval(f,x-e)));
error=abs(x2-x1);
x1=x2;
end
y=x1;
f(x)
ans =
-9.8696
>> raiz(@f,x)
ans =
3.1308
4)function y = f(x)
y = sin(x)-2*cos(2*x)+x^2-(pi^2-2);
function y= f2(a,b,n,f)
x=linspace(a,b,n+1);
suma=0;
for i=1:n
area=(x(i+1)-x(i))*(feval(f,x(i+1))+feval(f,x(i)))/2;
suma=suma+area;
endsuma
>> f2(pi,3*pi,101,@f)
suma =
219.2789
5)
function fxy = f (t,y)
fxy=0.235*(1-y)*(1+2*y)^2
function [t,y] = euler (f,a,b,yo,n)
h=(b-a)/n;
t(1)=a;
y(1)=yo;
for i=1:n
t(i+1) = t(i) + h;
y(i+1)= y(i) + h*feval(f,t(i),y(i));
end
[x,y]=euler(@ft,2,6,0,40)
x =
Columns 1 through 8
0 0.4000 0.8410 1.3250 1.8540 2.4300 3.0550 3.7310 Columns 9 through 16
4.4600 5.2440 6.0850 6.9850 7.9460 8.9700 10.0590 11.2150
Columns 17 through 24
12.4400 13.7360 15.1050 16.5490 18.0700 19.6700 21.3510 23.1150
Columns 25 through 32
24.9640 26.9000 28.9250 31.0410 33.2500 35.5540 37.9550 40.4550
Columns 33 through 40
43.0560 45.7600 48.5690 51.4850 54.5100 ...
Regístrate para leer el documento completo.