Info

# Storing values in a matrix

1 view (last 30 days)
Anna Zito on 14 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
I am using the ode45 function to solve a linearized and nonlinearized vibration equation. I need to plot both of them on the same graph. The only difference between the linearized and nonlinearized is a sin function.
In order to plot the two diagrams, my professor told me that I need to first save the solved differential equations in my main file, saved in two different matricies, say x and y. And then plot them using plot(t, x, t, y).
I do not know how to save them in matricies in order to make this work. I also only have the first ODE shown because I do not know how to incorporate a second one into the mix. Any help you could give would be greatly appreciated!!!
(The second ODE has the following form: [theta(2);
-(wn^2)*(theta(1))];
function thetadot = Vib(t,theta)
m=15;
l=2;
g=9.81;
d=l/2;
Io=(1/3)*m*(l^2);
wn=sqrt((m*g*d)/Io);
-(wn^2)*sin(theta(1))];
end
------------------------------------------------------------------
m=15;
l=2;
g=9.81;
d=l/2;
Io=(1/3)*m*(l^2);
wn=sqrt((m*g*d)/Io);
theta0=5;
t=[0:0.01:10];
figure (1);
plot(t,theta(:,1));

Stephan on 15 Oct 2020
% Constants
m=15;
l=2;
g=9.81;
d=l/2;
Io=(1/3)*m*(l^2);
wn=sqrt((m*g*d)/Io);
% function handle for linearized ode
Vib_lin = @(~,theta,wn) [theta(2); -(wn^2).*(theta(1))];
% function handle for nonlinearized ode
Vib_nonlin = @(~,theta,wn) [theta(2); -(wn^2).*sin(theta(1))];
% input data for ode45
theta0=5;
t=[0 10];
% solve linearized part
% solve nonlinearized part