Question

Problem #3: The Ralston method is a second-order method that can be used to solve an initial-value, first-orde ordinary diffe
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%% 3.1
function [t,y] = ralstomMethod(f,tSpan,y0)
% f(t,y) = dy/dt
% tSpan = time span
% y0 = initial value

y(1) = y0;
t = tSpan';

n = length(tSpan)-1;

for i =1:n
h = t(i+1)-t(i);
k1 = f(t(i),y(i));
k2 = f(t(i)+3*h/4,y(i)+3*k1*h/4);
  
y(i+1) = y(i) + h*(k1+2*k2)/3;
end

end

%% 3.2
clc
clear all
y0 = 3;
tf = 1.5;
h = 0.3;
% time span
tSpan = 0:h:tf;
% differential function dy/dt = f(t,y)
f =@(t,y) -1.5*y+7*exp(-0.4*t);
% solution of differential equation using ralstomMethod method
[t,y] = ralstomMethod(f,tSpan,y0);

%% 3.3
plot(t,y);
xlabel('time (s)');
ylabel('y(t)');
grid on
hold on
% solution of differential equation using ode45 function
[t,y] =ode45(f,tSpan,y0);
plot(t,y,'-r');
legend('Ralstom Method','ode45 function');

%% 3.4
figure
grid on
hold on
colour = ['r','b','g','k'];
h = [0.3 0.25 0.1 0.05];
for i = 1:length(h)
[t,y]=ralstomMethod(f,0:h(i):tf,y0);
plot(t,y,colour(i));
end
hold off
legend('h=0.3','h=0.25','h=0.1','h=0.05');
xlabel('time (s)');
ylabel('y(t)');

3.8 Ralstom Method ode45 function 3.7 3.6 3.5 3.4 3.31 3.2 3.1 0.5 1.5 time (s)3.8 h=0.3 -h=0.25 h=0.1 h=0.05 3.7 3.6 3.5 3.4 3.3 3.2 3.1 0.5 1.5 time (s)

Add a comment
Know the answer?
Add Answer to:
Problem #3: The Ralston method is a second-order method that can be used to solve an...
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
  • Problem #3: The Ralston method is a second-order method that can be used to solve an...

    Problem #3: The Ralston method is a second-order method that can be used to solve an initial-value, first-order ordinary differential equation. The algorithm is given below: 2 Yi+1 = yi + k +k2)h Where kı = f(ti,y;) 3 k2 = ft;+ -h, y; +-kih You are asked to do the following: 3.1 Following that given in Inclass activity #10a, develop a MATLAB function to implement the algorithm for any given function, the time span, and the initial value. 3.2 Use...

  • MATLAB CODE: Task 2 8y dt Solve the above ordinary differential equation (ODE) using Euler's method with step sizes of: 2. h 0.75 3. h 0.5 4. h 0.001 a) For each step size, plot the results at eac...

    MATLAB CODE: Task 2 8y dt Solve the above ordinary differential equation (ODE) using Euler's method with step sizes of: 2. h 0.75 3. h 0.5 4. h 0.001 a) For each step size, plot the results at each step starting from y(0) 3 to y(3). b) Plot on the same figure as part a) the analytical solution which is given by: 9 24 -8t c) Calculate and print the percentage error between the Euler's method and the analytical result...

  • Problem #4. The convective heat transfer problem of cold oil flowing over a hot surface can...

    Problem #4. The convective heat transfer problem of cold oil flowing over a hot surface can be described by the following second-order ordinary differential equations. d'T dT +0.83x = 0 dx? dx T(0)=0 (1) T(5)=1 where T is the dimensionless temperature and x is the dimensionless similarity variable. This is a boundary-value problem with the two conditions given on the wall (x=0, T(O) = 0) and in the fluid far away from the wall (x = 5, T(5) = 1)....

  • Problem #4. The convective heat transfer problem of cold oil flowing over a hot surface can...

    Problem #4. The convective heat transfer problem of cold oil flowing over a hot surface can be described by the following second-order ordinary differential equations. der 0 dx T(0)=0 (1) T(5)=1 where T is the dimensionless temperature and x is the dimensionless similarity variable. dr? +0.83, dT This is a boundary-value problem with the two conditions given on the wall (x=0, T(O) = 0) and in the fluid far away from the wall (x = 5,7/5) = 1). You are...

  • a can be skipped Consider the following second-order ODE representing a spring-mass-damper system for zero initial...

    a can be skipped Consider the following second-order ODE representing a spring-mass-damper system for zero initial conditions (forced response): 2x + 2x + x=u, x(0) = 0, *(0) = 0 where u is the Unit Step Function (of magnitude 1). a. Use MATLAB to obtain an analytical solution x(t) for the differential equation, using the Laplace Transforms approach (do not use DSOLVE). Obtain the analytical expression for x(t). Also obtain a plot of .x(t) (for a simulation of 14 seconds)...

  • Hello These are a math problems that need to solve by MATLAB as code Thank you...

    Hello These are a math problems that need to solve by MATLAB as code Thank you ! Initial Value Problem #1: Consider the following first order ODE: dy-p-3 from to 2.2 with y() I (a) Solve with Euler's explicit method using h04. (b) Solve with the midpoint method using h 0.4. (c) Solve with the classical fourth-order Runge-Kutta method using 0.4 analytical solution of the ODE is,·? solution and the numerical solution at the points where the numerical solution is...

  • Tylors Series Solve by using the second Order Taylors Series Method. Assume step size h=0.3 Consider...

    Tylors Series Solve by using the second Order Taylors Series Method. Assume step size h=0.3 Consider the RC circuit which is shown in the figure below. The charge Q across the capacitor at time to sec is o Coulomb, which is Q(0)=0 Coulomb, Given that C=2 F, R=12, and Vpc =5 V. The switch is closed at time t=0 sec, and the differential equation concerning the circuit is given as 99-1 -Q+ CV ).where Q is the charge stored in...

  • Ordinary differential equation: shooting method A steady-state heat balance for a 10 meter rod can be...

    Ordinary differential equation: shooting method A steady-state heat balance for a 10 meter rod can be presented as: AZ - 0.157 = 0 Use the shooting method with a second order Runge-Kutta algorithm (midpoint) to solve the above ODE. Use a step size of 5 m. T(0) = 240 and T(10) = 150. Hint: assume initial conditions of z(0) = -120 and z(0) = -60. Knowing the analytical solution: T = 3.016944e V0.15x + 236.9831e-V0.15x Comment on the obtained results...

  • Using the fourth order Runge-Kutta method (KK4 to solve a first order initial value problem NOTE:...

    Need help with this MATLAB problem: Using the fourth order Runge-Kutta method (KK4 to solve a first order initial value problem NOTE: This assignment is to be completed using MATLAB, and your final results including the corresponding M- iles shonma ac Given the first order initial value problem with h-time step size (i.e. ti = to + ih), then the following formula computes an approximate solution to (): i vit), where y(ti) - true value (ezact solution), (t)-f(t, v), vto)...

  • -1.2y 7e-03* from x tox 2.0 with the 2) Use Euler's method to solve the ODE...

    -1.2y 7e-03* from x tox 2.0 with the 2) Use Euler's method to solve the ODE initial condition y3 at x0 dx a) Solve by hand using h b) Write a MATLAB program in a script file that solves the equation using h-0.1 and find y(1.5). c) Use the program from part (b) to solve the equation using h= 0.01 and h = 0.001 and findy(1,5). 0.5 and find y(2). d) The exact solution to the IVP is given by...

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