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 个)

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 个评论

can you maybe write an example code? I dont understand how this works
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
tspan = 1×25
0 0.8333 1.6667 2.5000 3.3333 4.1667 5.0000 5.8333 6.6667 7.5000 8.3333 9.1667 10.0000 10.8333 11.6667 12.5000 13.3333 14.1667 15.0000 15.8333 16.6667 17.5000 18.3333 19.1667 20.0000
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
tspan = 1×250
0 0.0803 0.1606 0.2410 0.3213 0.4016 0.4819 0.5622 0.6426 0.7229 0.8032 0.8835 0.9639 1.0442 1.1245 1.2048 1.2851 1.3655 1.4458 1.5261 1.6064 1.6867 1.7671 1.8474 1.9277 2.0080 2.0884 2.1687 2.2490 2.3293
[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!

Translated by