Question
where is says use euler2, for that please create a function file for euler method and use that! please help out with this! please! screenahot the outputs and code! thanks!!!
The van der Pol equation is a 2nd-order ODE that describes self-sustaining oscillations in which energy is withdrawn from lar
0 0
Add a comment Improve this question Transcribed image text
Answer #1

File 'euler2.m':

function [y, z] = euler2(dydt, dzdt, ti, tf, h, y0, z0)
n = (tf-ti)/h;
t = ti:h:tf;
y(1) = y0; z(1) = z0;
for i=1:n
m = dydt(t(i), y(i), z(i));
n = dzdt(t(i), y(i), z(i));
  
y(i+1) = y(i) + h*m;
z(i+1) = z(i) + h*n;
end
end

File 'Q3b.m':

close all
clear
clc

mu = 1;
dydt = @(t,y,z) z;
dzdt = @(t,y,z) mu*(1 - y^2)*z - y;
H = [0.25 0.125 0.0625];
ti = 0; tf = 30; y0 = 1; z0 = 1;
figure(4)
for i = 1:length(H)
h = H(i);
[y, z] = euler2(dydt, dzdt, ti, tf, h, y0, z0);
subplot(211), plot(ti:h:tf, y), hold on
subplot(212), plot(ti:h:tf, z), hold on
end
subplot(211), xlabel('t'), ylabel('y')
legend('h = 0.25', 'h = 0.125', 'h = 0.0625', 'Location', 'northwest'), hold off
subplot(212), xlabel('t'), ylabel('dy/dt')
legend('h = 0.25', 'h = 0.125', 'h = 0.0625', 'Location', 'northwest'), hold off

Output Figure (4):

3 h 0.25 h0.125 h 0.0625 0 10 15 25 30 20 h 025 h 0.125 h 0.0625 -1 -3 10 15 20 25 30

File 'Q3c.m':

close all
clear
clc

MU = [0.01 0.1 0.5 1 2 3 5];
h = 0.01;
ti = 0; tf = 30; y0 = 1; z0 = 1;
figure(5)
colourmap = [1 0 0; 0 1 0; 0 0 1; 1 1 0; 1 0 1; 0 1 1; 0 0 0];
for i = 1:length(MU)
mu = MU(i);
dydt = @(t,y,z) z;
dzdt = @(t,y,z) mu*(1 - y^2)*z - y;
[y, z] = euler2(dydt, dzdt, ti, tf, h, y0, z0);
plot(z, y, 'Color', colourmap(i,:)), hold on
end
xlabel('y'), ylabel('dy/dt')
legend('\mu = 0.01', '\mu = 0.1', '\mu = 0.5', '\mu = 1', '\mu = 2', '\mu = 3', '\mu = 5', 'Location', 'northwest')
axis('square')
hold off

Output Figure (5):

8 6 4 0 015 0001235 -6 -8 2 0 pAp

Add a comment
Know the answer?
Add Answer to:
where is says use euler2, for that please create a function file for euler method and use that! please help out with t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT