1 / 5100%
Exercise 1
theta=[0;pi/4;pi/2;3*pi/4;5*pi/4];
r=2;
x = r*cos(theta)
y = r*sin(theta)
sqrt(x.^2+y.^2)
ans=
2 22222
Exercise 2A
t=linspace(1,10,91);
y=(exp((t./10)).*sin(t))./(t.^2+1)
plot(y,'k')
title('y=[(e^(t/10))(sin(t)]/(t^2+1)')
Exercise 2B
t=linspace(1,10,91);
y=(exp((t./10)).*sin(t))./(t.^2+1)
plot(t,y,'o-')
title('y=[(e^(t/10))(sin(t)]/(t^2+1)')
Exercise 3
t=0:0.1:20;
x=sin(t);
y=cos(t);
z=t;
plot3(x,y,z)
Exercise 4
x=0:0.1:pi;
y=cos(x);
z=1-x.^2/2+x.^4/24;
plot(x,y,'r',x,z,'--')
gridon
Exercise 5
x=(0:0.1:4);
y1=myfunc1(x,-1);
y2=myfunc1(x,0);
y3=myfunc1(x,1);
plot(x,y1,'c',x,y2,'m',x,y3,'y');
title('Solutions to dy/dx=x+2');
legend('C=-1','C=0','C=1')
myfuncl:
function [ y ] = myfunc1( x,C )
y=(x.^2)/2+2*x+C;
end
Exercise 6A
f=inline('x^3+(y*exp(x))/(x+1)','x','y')
f(2,-1)
f =
Inline function:
f(x,y) = x^3+(y*exp(x))/(x+1)
ans =
5.5370
Exercise 6B
myfunc3(2,-1)
ans =
5.5370
myfunc3:
function [ dydx ] = myfunc3( x,y )
dydx=x.^3+(y*exp(x))/(x+1);
end
Students also viewed