How can i plot a differential setting my own sample time?
Show older comments
I have several columns containing Information like my Voltage, my charge, current and capacity
I need to plot the dU/dQ in the y-axis in relation to my Q in the x-axis, and need to be able to choose my sample rate in which I plot this Data.
Does anyone know how this can be achieved?
Answers (1)
Star Strider
on 7 Dec 2021
Yes.
Define the ‘tspan’ argument as a vector with more than 2 elements, for example to go from 0 to 5 with 15 sampling pints, all regularly-spaced —
tspan = linspace(0, 5, 15)
The numeric ordinary differential equation integrators will calculate many values in the system being integrated, however will interpolate and return only the values corresponding to the values in the‘tspan’ vector.
.
2 Comments
Bernardo Farfan Valencia
on 7 Dec 2021
Sure!
dydt = @(t,y) [y(2); (1-y(1)^2)*y(2)-y(1)]; % Ordinary Differential Equation System
tspan = linspace(0, 20 ,25) % Span Sampled 25 Times
ic = [2 0]; % Initial Conditions Vector
[t,y] = ode45(dydt, tspan, ic);
figure
plot(t, y, '.-')
grid
tspan = linspace(0, 20, 250) % Span Sampled 250 Times
[t,y] = ode45(dydt, tspan, ic);
figure
plot(t, y, '.-')
grid
Of course the ‘tspan’ vector does not have to be created this way. It can be anything desired, however I believe the vector elements must be unique and monotonically increasing.
This uses the van der Pol oscillator example from the documentation.
.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
