How can i plot a differential setting my own sample time?
显示 更早的评论
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?
回答(1 个)
Star Strider
2021-12-7
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 个评论
Bernardo Farfan Valencia
2021-12-7
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.
.
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

