Question

Using MATLAB_R2017a, solve #3 using the differential equation in question #2 using Simulink, present the model and result.

2. Differential Equation (5 points) Using (i) Eulers method and (ii) modified Eulers method, both with step size h-0.01, to

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

Text :-

dxdt = @(t,x) sqrt(x*t/(x.^2+t.^2));
h = 0.01;
t = 0:h:2;      % time vector (t0,t1,...tn)
x_euler = zeros(1,length(t));      % Initializing Euler solution vector having same size as time vector
x_mod_euler = zeros(1,length(t));  % Initializing modified Euler solution

x_euler(1) = 1;             % Initial Conditions
x_mod_euler(1)=1;

for k = 2:length(t)
x_euler(k) = x_euler(k-1) + h*dxdt(t(k-1),x_euler(k-1));
x_mod_euler(k) = x_mod_euler(k-1) + (h/2)*(dxdt(t(k-1),x_mod_euler(k-1)) + dxdt(t(k),x_euler(k)));
end

% Comparing Results in table (Intermediate Values)
fprintf("\n %8s %16s %20s\n","t","Euler","Modified Euler")
fprintf(" %8.2f %16.6f %20.6f\n",[t(1:20:end)',x_euler(1:20:end)',x_mod_euler(1:20:end)'].')
% Ploting Both on Same Graph
p = plot(t,x_euler,'-.',t,x_mod_euler,'--');
p(1).LineWidth = 1.6;       p(2).LineWidth = 1.6;
legend(["Euler Method","Modified Euler Method"],'Location','Best')
xlabel('t');    ylabel("x(t)");      title("Euler Method vs Modifed Euler Method")

Simulink :-

1 Scope Integrator Clock u(2) sqrt(u(1) u(2)/(u(1)2+ u(2)A2)) Fcn Bus Creator

Euler Method vs Modifed Euler Method 2.4 r 2.2 1.8 1.6 1.4 Euler Method Modified Euler Method 1.2 0 0.2 0.40.6 0.8 1 12 1.416

Add a comment
Know the answer?
Add Answer to:
Using MATLAB_R2017a, solve #3 using the differential equation in question #2 using Simulink, pres...
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
Active Questions
ADVERTISEMENT