In: Advanced Math
Solve the cauchy problem (x^2)*y''-9*x*y'+21*y=0, y'(1)=5 on the interval (1,3). Plot the graphs of y(x) and y'(x)
Please Provide only MATLAB Code.
%%Matlab code for solving ode
clear all
close all
%Answering question
%Initial conditions for ode
u0=[0;5];
%Solution for equation 1. using ode45
%minimum and maximum
time span
xspan=[1 3];
%Solution of ODEs using
ode45 matlab function
[x1,sol1]= ode45(@(x,y)
odefcn1(x,y), xspan, u0);
%Plotting the
solution
figure(1)
plot(x1,sol1(:,1))
title('x vs. y(x) plot
for ode45')
xlabel('x')
ylabel('y(x)')
figure(2)
plot(x1,sol1(:,2))
title('x vs. dy(x)/dx
plot for ode45')
xlabel('x')
ylabel('dy(x)/dx')
%Function for evaluating the ODE
function du1dt = odefcn1(x,y)
eq1=y(2);
eq2=(9./x).*y(2)-(21./x.^2).*y(1);
%Evaluate the ODE for our present problem
du1dt = [eq1;eq2];
end
%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%