Professional Documents
Culture Documents
N = 5
for i = 1:N
Y(i+1) = Y(i) + h*(Y(i) + (T(i)).^3);
end
xp=a:2:b;
ya = 7*exp(xp) - (xp).^3 - 3*(xp).^2 - 6*(xp) - 6
plot(T,Y,xp,ya)
legend('EEM','Analytical')
hold on
For 9b:
%Given functions
f=@(t) 7*exp(t)-t.^3-3*t.^2-6*t-6;
g={@(t,x) x + t^3, @(t,x) x + t^3 + 3*t^2, @(t,x) x + t^3 + 3*t^2 + 6*t,
@(t,x) x + t^3 + 3*t^2 + 6*t + 6, @(t,x) x + t^3 + 3*t^2 + 6*t + 6};
a = linspace(0,10);
x = linspace(0,10,n+1);
n = 5; %Value of subintervals
h = 2; %Step size (difference bet x values)
t1= [1];
for k = 2:n+1
for m = 1:5
tay5(k) = tay5(k) + g{m}(x(k-1),tay5(k-1))*(h^m)/(factorial(m));
end
end
plot(x,tay5,a,f(a),'--',x,t1,':');
xlabel('Interval [a,b]')
legend('Taylor 5','Analytical','EEM or Taylor 1')
For 9c:
a=0;
y0 = 1;
b = 10;
h = 2;
N = 5;
for i=1:N
k1 = Y(i)+(T(i)).^3;
k2 = (Y(i)+k1*h) + (T(i)+h).^3
Y(i+1) = Y(i) + 0.5*h*(k1 + k2)
end
xp=a:2:b;
ya = 7*exp(xp) - (xp).^3 - 3*(xp).^2 - 6*(xp) - 6
plot(T,Y,xp,ya,T,W)
legend('Modified Euler','Analytical','Runge-Kutta')