Question

MATLAB

I need the input code and the output. Thanks.

7. Modify the Eulers method MATLAB code presented in the Learning activity video called Using Eulers Method on Matlab (loca

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

The MatLab code for the Euler's method -

function Euler(func, y0, del, tf)
t = 0: delt: tf;

// t= initial point
y(1) = y0;
for i = 1:length(t)-1
//Assuming the function is dependent only on the x-axis, and not on y axis or it's values
y(i+1) = y(i) + del/2*(feval(func, t(i)) + feval(func, t(i+1)));
end
plot(t, y);
xlabel('time')
ylabel('y')
disp(y(end))

Modified Euler Algorithm:
The modified Euler method starts with an Euler step, giving a provisional value for wi+1 at the next time ti+1:

The step actually taken looks like an Euler step, but with f replaced by the average of f at the starting point of the step and f at the provisional point:

function euler(func, y0, delt, tf)
t = 0:delt:tf;
y(1) = y0;
for i = 1:length(t)-1
% Assuming function is dependent only on the x-axis, and not on corresponding y-values
y(i+1) = y(i) + delt/2*(feval(func, t(i)) + feval(func, t(i+1)));
end
plot(t, y);
xlabel('time')
ylabel('y')
disp(y(end))

Modified Euler Algorithm:
The modified Euler method starts with an Euler step, giving a provisional value for wi+1 at the next time ti+1:
where -

W' i+1= Wi+hf(ti,Wi)

and Wi+1 = Wi + h/2(f(ti,Wi) + f( ti+1 , W' i+1)

where h varies from 0.1 to .01

Add a comment
Know the answer?
Add Answer to:
MATLAB I need the input code and the output. Thanks. 7. Modify the Euler's method MATLAB...
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