Question

9imereal Condltion and note the behavior of the system. xercise 5. For this exercise you will approximate the solution of an

using improved eulers method using excel

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for Euler and Heuns method for 2d clear all close all 888888움움88,,88움움8888888888움움888888888888888888888888888888%initial guess x_0=0; yー0-0 ; iteration for x and y using improved Euler method s_huen (1)-x-0 ; y-hue n (1)-y-0; t_huen (1)Improved Euler solution plot for w 1 25 15 10 10 15 10 20 30 time in sec. 50 Improved Euler solution plot for w-1.1 10 10 50

%Matlab code for Euler and Heun's method for 2d
clear all
close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%functions for improved Euler method for w=1
w=1;
f=@(t,x,y) y;
g=@(t,x,y) -x+cos(w*t);

%step size
h=0.1;

%Initial guess
x_0=0; y_0=0;

%iteration for x and y using improved Euler method
x_huen(1)=x_0; y_huen(1)=y_0;
t_huen(1)=0; t_end=50;
n=(t_end-t_huen)/h;
for i=1:n
  
    t_huen(i+1)=t_huen(i)+h;
    m1=f(t_huen(i),x_huen(i),y_huen(i));
    m2=g(t_huen(i),x_huen(i),y_huen(i));
  
    p1=f(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
    p2=g(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
  
    x_huen(i+1)=x_huen(i)+(h/2)*(m1+p1);
    y_huen(i+1)=y_huen(i)+(h/2)*(m2+p2);
  
end

figure(1)
plot(t_huen,x_huen)
xlabel('time in sec.')
ylabel('x(t)')
title('Improved Euler solution plot for w=1')

clear x_huen; clear y_huen; clear t_huen

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%functions for improved Euler method for w=1
w=1.1;
f=@(t,x,y) y;
g=@(t,x,y) -x+cos(w*t);

%step size
h=0.1;

%Initial guess
x_0=0; y_0=0;

%iteration for x and y using improved Euler method
x_huen(1)=x_0; y_huen(1)=y_0;
t_huen(1)=0; t_end=150;
n=(t_end-t_huen)/h;
for i=1:n
  
    t_huen(i+1)=t_huen(i)+h;
    m1=f(t_huen(i),x_huen(i),y_huen(i));
    m2=g(t_huen(i),x_huen(i),y_huen(i));
  
    p1=f(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
    p2=g(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
  
    x_huen(i+1)=x_huen(i)+(h/2)*(m1+p1);
    y_huen(i+1)=y_huen(i)+(h/2)*(m2+p2);
  
end

figure(2)
plot(t_huen,x_huen)
xlabel('time in sec.')
ylabel('x(t)')
title('Improved Euler solution plot for w=1.1')

clear x_huen; clear y_huen; clear t_huen

fprintf('\tFor w=1 the period of envelop is higher than that of w=1.1 \n')

%%%%%%%%%%%%%%%%%%%%%%%% End of code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
9imereal Condltion and note the behavior of the system. xercise 5. For this exercise you will app...
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