For the DE: dy/dx=2x-y    y(0)=2     with h=0.2, solve for y using each method below in the range of 0 <= x <= 3: Q1) Using Matlab to employ the Euler Method (Sect 2.4)  Q2) Using Matlab to employ the Improved Euler Method (Sect 2.5 close all clear all % Let's program exact soln for i=1:5 x_exact(i)=0.5*i-0.5; y_exact(i)=-x_exact(i)-1+exp(x_exact(i)); end plot(x_exact,y_exact,'b') % now for Euler's h=0.5 x_EM(1)=0; y_EM(1)=0; for i=2:5 x_EM(i)=x_EM(i-1)+h; y_EM(i)=y_EM(i-1)+(h*(x_EM(i-1)+y_EM(i-1))); end hold on plot (x_EM,y_EM,'r') % Improved Euler's Method h=0.5 x_IE(1)=0; y_IE(1)=0; for i=2:1:5     kA=x_IE(i-1)+y_IE(i-1);     u=y_IE(i-1)+h*kA;     x_IE(i)=x_IE(i-1)+h;     kB=x_IE(i)+u;     k=(kA+kB)/2;     y_IE(i)=y_IE(i-1)+h*k; end hold on plot(x_IE,y_IE,'k')

Elements Of Electromagnetics
7th Edition
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Sadiku, Matthew N. O.
ChapterMA: Math Assessment
Section: Chapter Questions
Problem 1.1MA
icon
Related questions
Question

For the DE: dy/dx=2x-y    y(0)=2     with h=0.2, solve for y using each method below in the range of 0 <= x <= 3:

Q1) Using Matlab to employ the Euler Method (Sect 2.4) 

Q2) Using Matlab to employ the Improved Euler Method (Sect 2.5

close all

clear all

% Let's program exact soln

for i=1:5

x_exact(i)=0.5*i-0.5;

y_exact(i)=-x_exact(i)-1+exp(x_exact(i));

end

plot(x_exact,y_exact,'b')

% now for Euler's

h=0.5

x_EM(1)=0;

y_EM(1)=0;

for i=2:5

x_EM(i)=x_EM(i-1)+h;

y_EM(i)=y_EM(i-1)+(h*(x_EM(i-1)+y_EM(i-1)));

end

hold on

plot (x_EM,y_EM,'r')

% Improved Euler's Method

h=0.5

x_IE(1)=0;

y_IE(1)=0;

for i=2:1:5

    kA=x_IE(i-1)+y_IE(i-1);

    u=y_IE(i-1)+h*kA;

    x_IE(i)=x_IE(i-1)+h;

    kB=x_IE(i)+u;

    k=(kA+kB)/2;

    y_IE(i)=y_IE(i-1)+h*k;

end

hold on

plot(x_IE,y_IE,'k')

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Thermodynamic Relations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, mechanical-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Elements Of Electromagnetics
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Control Systems Engineering
Control Systems Engineering
Mechanical Engineering
ISBN:
9781118170519
Author:
Norman S. Nise
Publisher:
WILEY
Mechanics of Materials (MindTap Course List)
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:
9781337093347
Author:
Barry J. Goodno, James M. Gere
Publisher:
Cengage Learning
Engineering Mechanics: Statics
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:
9781118807330
Author:
James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:
WILEY