using gradient with ode45

6 次查看(过去 30 天)
i have this code, where gradient(u,t) should be the derivative of u:
function [xdot]=pid_practica9_ejercicio3_ec_diferencial_prueba2(t,x)
Vp=5;
u=Vp*sin(2*pi*t)+5;
xdot = [
x(2, :);
1.776*0.05252*20*gradient(u,t)-10*x(1, :)-7*x(2, :);
];
%[t,x]=ode45('pid_practica9_ejercicio3_ec_diferencial_prueba2',[0,10],[0,0])
% plot(t,x)
but in the solution i get only zeros (and they shouldn't be)
is it possible to work with a derivative in the definition of a diferential equation like i do?
  2 个评论
madhan ravi
madhan ravi 2018-7-7
Can you post the question to solve?
jose luis guillan suarez
编辑:Walter Roberson 2018-7-7
this is the equation:
Vp=5;
u=Vp*sin(2*pi*t)+5;
x''=-7x'-10x+1.776*0.05252*20*u'

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-7-7
The t and x values passed into your function will be purely numeric, with t being a scalar and x being a vector the length of your initial conditions (so a vector of length 2 in this case.)
You calculate u from the scalar t value, and you pass the scalar u and scalar t into gradient -- the numeric gradient routine. The numeric gradient() with respect to scalar F and scalar H is always 0.
  8 个评论
jose luis guillan suarez
my problem is that i'm trying to represent this system with differential equations and with ode45, where the derivative of u is needed (if im not commiting a mistake), and it is perfectly representable in matlab using the blocks (in the 's' domain) and with the input as a step input (which is very similar to a squared waveform)
jose luis guillan suarez
i simulated this system with a step input with this instructions:
>> num1=20
num1 =
20
>> den1=[1 7 10]
den1 =
1 7 10
>> sys1=tf(num1,den1)
sys1 =
20
--------------
s^2 + 7 s + 10
Continuous-time transfer function.
>> num2=[1 0]
num2 =
1 0
>> den2=1
den2 =
1
>> sys2=tf(num2,den2)
sys2 =
s
Continuous-time transfer function.
>> sys=series(sys1,sys2)
sys =
20 s
--------------
s^2 + 7 s + 10
Continuous-time transfer function.
>> step(sys)
and i obtain this response:
but it seems to be impossible to simulate it with diferential equations

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by