Question

Is it possible to do this without matlab?3In modelling the velocity y of a chain slipping off a horizontal platform, the differential equation y- 10/y - y/x is deriv

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


Matlab code for Euler, Improved Euler and RK4 method clear all close all %Function for which solution have to do f-e(x,y) 10.x eval-2; n=(x-eval-X)/h; % at what point we have to evaluate % Number of steps for i-1:n RK4 Steps k1-h double(f (x,y)) k2-hThe solution using Euler Method for h-0.050 at x(2.0) is 3.492230 The solution using improved Euler Method for h=0.050 at x (

%%Matlab code for Euler, Improved Euler and RK4 method
clear all
close all
%Function for which solution have to do
f=@(x,y) 10./y-y./x;
hh=[0.05 0.025];

for ii=1:2
    %Euler method
    h=hh(ii);         % amount of intervals
    x=1;             % initial x
    y=1;             % initial y
    x_eval=2;        % at what point we have to evaluate
    n=(x_eval-x)/h; % Number of steps
    x2(1)=x;
    y2(1)=y;
    for i=1:n
        %Eular Steps
        m=double(f(x,y));
        x=x+h;
        y=y+h*m;
        x2(i+1)=x;
        y2(i+1)=y;
    end
    yy(ii,1)=y2(end);
    fprintf('\n\tThe solution using Euler Method for h=%.3f at x(%.1f) is %f\n',h,x2(end),y2(end))

    %Improved Euler method
    x=1;             % initial x
    y=1;             % initial y
    x_eval=2;        % at what point we have to evaluate
    n=(x_eval-x)/h; % step size
    x3(1)=x;
    y3(1)=y;
    for i=1:n
    %improved Euler steps
       m1=double(f(x,y));
       m2=double(f((x+h),(y+h*m1)));
       y=y+double(h*((m1+m2)/2));
       x=x+h;
       y3(i+1)=y;
       x3(i+1)=x;
    end
    yy(ii,2)=y3(end);
  
    fprintf('\tThe solution using improved Euler Method for h=%.3f at x(%.1f) is %f\n',h,x3(end),y3(end))
  
    %RK4 method
    x=1;             % initial x
    y=1;             % initial y
    x_eval=2;        % at what point we have to evaluate
    n=(x_eval-x)/h; % Number of steps
    x4(1)=x;
    y4(1)=y;
    for i=1:n
    %RK4 Steps
       k1=h*double(f(x,y));
       k2=h*double(f((x+h/2),(y+k1/2)));
       k3=h*double(f((x+h/2),(y+k2/2)));
       k4=h*double(f((x+h),(y+k3)));
       dx=(1/6)*(k1+2*k2+2*k3+k4);
       x=x+h;
       y=y+dx;
       x4(i+1)=x;
       y4(i+1)=y;

    end
    yy(ii,3)=y4(end);
    fprintf('\tThe solution using Runge Kutta 4 for h=%.3f at x(%.1f) is %f\n',h,x4(end),y4(end))

end
%exact solution
syms y(x)
eqn = diff(y,x) == 10/y-y/x;
cond = y(1) == 1;
y_ext(x)=dsolve(eqn,cond);

fprintf('\n\tExact solution for y(2) at x=2 is %f.\n',y_ext(2))

%Table for absolute error
fprintf('\n\n\t Absolute error of Approximations to y(2)\n')
fprintf('\tMethod        \th=0.005\th=0.025\tRatio\n\n')
v1=abs(y_ext(2)-yy(1,1)); v2=abs(y_ext(2)-yy(2,1));
fprintf('\tEuler         \t%e\t%e\t%f\n',v1,v2,v1/v2)
v1=abs(y_ext(2)-yy(1,2)); v2=abs(y_ext(2)-yy(2,2));
fprintf('\tImproved Euler\t%e\t%e\t%f\n',v1,v2,v1/v2)
v1=abs(y_ext(2)-yy(1,3)); v2=abs(y_ext(2)-yy(2,3));
fprintf('\tRunge kutta   \t%e\t%e\t%f\n',v1,v2,v1/v2)


%%Plotting solution using Euler method
figure(1)
hold on
plot(x2,y2,'Linewidth',2)
plot(x3,y3,'Linewidth',2)
plot(x4,y4,'Linewidth',2)
xlabel('x')
ylabel('y(x)')
title('Solution plot y vs. x')
legend('Euler Method','Modified Euler','RK4 Method','Location','northwest')
grid on


%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Is it possible to do this without matlab? 3In modelling the velocity y of a chain slipping off a horizontal platform, th...
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
  • hand written solution only (not computerised) if not possible then please refund the question becs i have already re...

    hand written solution only (not computerised) if not possible then please refund the question becs i have already recieved a computerised solution from you but i dont understand. 3In modelling the velocity y of a chain slipping off a horizontal platform, the differential equation y, 10/y-y/x is derived. Suppose the initial condition is y( 1-1 (a) Euler's method for solving yf(x), y(xoyo, is given by yn+n+hf(an,yn), where h is a fixed stepsize, xn xo + nh, and yn y(xn). Apply...

  • Numerical Methods for Differential Equations - Please post full correct solution!!! - need to use MATLAB...

    Numerical Methods for Differential Equations - Please post full correct solution!!! - need to use MATLAB 3. (a) Write Matlab functions to integrate the initial value problem y = f(x,y), y(a) = yo, on an interval [a, b] using: • Euler's method • Modified Euler • Improved Euler • Runge Kutta 4 It is suggested that you implement, for example, Improved Euler as [x, y) = eulerimp('f', a, yo, b, stepsize), where (2,y) = (In, Yn) is the computed solution....

  • Use Improved Euler for first question, Runge- Katta for 2nd one. Thank you In each of...

    Use Improved Euler for first question, Runge- Katta for 2nd one. Thank you In each of Problems 7 through 12, find approximate values of the solution of the given initial value problem at t-0.5,1.0, 1.5, and 2.0 (a) Use the improved Euler method with h 0.025 (b) Use the improved Euler method with h-0.0125 In each of Problems 7 through 12, find approximate values of the solution of the given initial value problem at0.5,1.0, 1.5, and 2.0. Compare the results...

  • di 2 y(0) = 1 Matlab. Apply Eulers method with step size h = 0.1 on...

    di 2 y(0) = 1 Matlab. Apply Eulers method with step size h = 0.1 on [0, 1] to the initial value problem listed above, in #3. a Print a table of the t values, Euler approximations, and error at each step. Deduce the order of convergence of Euler's method in this case.

  • Complete using MatLab 1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's...

    Complete using MatLab 1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's Method and the second order Runge-Kutta method, for t E [0, 1] with a step size of h 0.05, approximate the solution to the initial value problem. Plot the true solution and the approximate solutions on the same figure. Be sure to label your axis and include an a. appropriate legend b. Verify that the analytic solution to the differential equation is given by...

  • Matlab & Differential Equations Help Needed I need help with this Matlab project for differential equations. I've got 0 experience with Matlab other than a much easier project I did in another...

    Matlab & Differential Equations Help Needed I need help with this Matlab project for differential equations. I've got 0 experience with Matlab other than a much easier project I did in another class a few semesters ago. All we've been given is this piece of paper and some sample code. I don't even know how to begin to approach this. I don't know how to use Matlab at all and I barely can do this material. Here's the handout: Here's...

  • Consider the initial value problem below to answer to following. a) Find the approximations to y(0.2)...

    Consider the initial value problem below to answer to following. a) Find the approximations to y(0.2) and y(0.4) using Euler's method with time steps of At 0.2, 0.1, 0.05, and 0.025 b) Using the exact solution given, compute the errors in the Euler approximations at t 0.2 and t 0.4. c) Which time step results in the more accurate approximation? Explain your observations. d) In general, how does halving the time step affect the error at t 0.2 and t...

  • Question 1: Given the initial-value problem 12-21 0 <1 <1, y(0) = 1, 12+10 with exact...

    Question 1: Given the initial-value problem 12-21 0 <1 <1, y(0) = 1, 12+10 with exact solution v(t) = 2t +1 t2 + 1 a. Use Euler's method with h = 0.1 to approximate the solution of y b. Calculate the error bound and compare the actual error at each step to the error bound. c. Use the answers generated in part (a) and linear interpolation to approximate the following values of y, and compare them to the actual value...

  • A use Euler's method with each of the following step sizes to estimate the value of y 0.4 where y...

    a use Euler's method with each of the following step sizes to estimate the value of y 0.4 where y is the solution of the initial value problem y -y, y 0 3 カー0.4 0.4) (i) y10.4) (in) h= 0.1 b we know that the exact solution of the initial value problem n part a s yー3e ra , as accurately as you can the graph of y e r 4 together with the Euler approximations using the step sizes...

  • [7] 1. Consider the initial value problem (IVP) y′(t) = −y(t), y(0) = 1 The solution to this IVP ...

    [7] 1. Consider the initial value problem (IVP) y′(t) = −y(t), y(0) = 1 The solution to this IVP is y(t) = e−t [1] i) Implement Euler’s method and generate an approximate solution of this IVP over the interval [0,2], using stepsize h = 0.1. (The Google sheet posted on LEARN is set up to carry out precisely this task.) Report the resulting approximation of the value y(2). [1] ii) Repeat part (ii), but use stepsize h = 0.05. Describe...

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