Professional Documents
Culture Documents
Function writing
Anonymous functions
f= @(x) x + cos(2*x);
f(1)
f(1:7);
ezplot(f)
fplot(f)
Analytical method)
clear
clc
syms y(x)
eqn=diff(y)== 3*x^2+3;
cond=y(0)==0;
ysol=dsolve(eqn,cond);
fplot(ysol)
1. Euler’s normal method
hold on
___________________________________________________
2. Example ODE 45;
f=@(x,y) (x-y)^2;
[x,y]= ode45(f, 0:0.01:0.5,0.5);
plot(t,x(:,1),'r',t,x(:,2),'b'),legend('displacemen
t','velocity')
f =@(t,x) [x(3);x(4);0.2*(-12*x(3)-5*x(1)+8*x(4)+4*x(2));0.33*(-
8*x(4)-4*x(2)+8*x(3)+4*x(1))];
[t,x]= ode45(f,0:0.1:7,[5,1,-3,2]);
plot(t,x), legend('dispm1','dispm2','velm1','velm2')