Question

I'm still trying to learn how to use matlab but I'm not sure how to do this at all. I am to implement three different explicit methods for approximating an IVP using Eulers, Runge-Kutta 4th order method, and the trapezoidal method using the same parameters. I'd much appreciate having just the Euler methods. but having all three done would be greatly appreciated and will give a great rating!function y forward_euler (n, m, a, b, eta,F) % Use the forward Euler method to approximate the solution of % the initial valu

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

Answer:)

Code:

function y = forwardeuler(n,m,a,b,eta,F)
    y = zeros(n,m); %pre-allocate the result with all zeros
    if(size(eta,2) ~= 1)
        y(:,1) = eta'; %set the first column to be initial condition
    else
        y(1) = eta;
    end
    h = (b-a)/m; %define the step-size
    t = a:h:b-h; %set up the time vector;
    for i = 1:m-1
        y(:,i+1) = y(:,i) + h*F(t(i),y(:,i)')'; %euler update step
                                                %note that we have
                                                %transposed the F-output so
                                                %that the dimensions match
    end
end

Add a comment
Know the answer?
Add Answer to:
I'm still trying to learn how to use matlab but I'm not sure how to do this at all. I am to imple...
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