How do I access and plot thetadot vs. time from function I have created?
Show older comments
function thetadot= oscltr(t,theta)
A= [0 0 0.5 0 0 0; 0.5 0 0 0 0 0.5; 0.5 0.5 0 0 0 0; 0 0.5 0 0 0 0; 0 0 0.5 0 0 0; 0 0 0 0.5 0.5 0]; % edge weight matrix
D= [0.5 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0; 0 0 0 0.5 0 0; 0 0 0 0 0.5 0; 0 0 0 0 0 1]; %Diagonal in-degree matrix
L= D-A; %Laplacian matrix
N=6;
K=50;
wi=[1; 1.1 ;0.9; 0.85; 2; 2.1];
thetadot=wi-(K/N)*L*theta;
end
Accepted Answer
More Answers (1)
Ghazwan
on 8 Oct 2022
Edited: Walter Roberson
on 8 Oct 2022
There are several ways, one of whith would be
Dtheta=diff(theta) %theta = values
Dtime=diff(time) %time = time values.
ThetaDot = Dtheta./Dtime.
plot(Dtheta,time) % you have to be careful in case there is 0/0 somewhere.
2 Comments
Walter Roberson
on 8 Oct 2022
I recommend using gradient() instead. The timestep for ode45 is typically irregular.
Torsten
on 8 Oct 2022
Just call the function with the values for theta of your choice.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!