Show to use ode45 built-in function in MATLAB to solve the following ODE problem: dydx=x^2 / y...

Free

80.2K

Verified Solution

Question

Mechanical Engineering

Show to use ode45 built-in function in MATLABto solve the following ODE problem:

dydx=x^2 / y y(0)=2  

Calculate y(x) for 0 ? x ? 20 and compare the results toanalytical solution y = sqrt((2x^3 / 3) + 4)

Answer & Explanation Solved by verified expert
4.0 Ratings (742 Votes)

The Matlab code is given below:

Matlab Code:

%Start of code
xfinal = 20; % Final value of x
xspan = [0 xfinal];
y0 = 2; % Initial value of y
F = @(x,y) (x^2/y); % Differential function
[X,Y] = ode45(F,xspan,y0); % Solve the equation

%Results at specified vlaues of x
Y0 = Y(X == 0)
Y0_analytical = ((2*0.^3/3)+4).^0.5
Y20 = Y(X == 20)
Y20_analytical = ((2*20.^3/3)+4).^0.5

% Plot both the solutions
plot(X,Y,'.')
hold on
plot(X,((2*X.^3/3)+4).^0.5,'r')
xlabel('X')
ylabel('Y')
legend('ode45','analytical solution'
% End of code

As it can be noticed, the solution obtained using ode45 is close to the analytical solution


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students