Clear Filters
Clear Filters

using gradient with ode45

6 views (last 30 days)
jose luis guillan suarez
jose luis guillan suarez on 6 Jul 2018
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 Comments
madhan ravi
madhan ravi on 7 Jul 2018
Can you post the question to solve?
jose luis guillan suarez
jose luis guillan suarez on 7 Jul 2018
Edited: Walter Roberson on 7 Jul 2018
this is the equation:
Vp=5;
u=Vp*sin(2*pi*t)+5;
x''=-7x'-10x+1.776*0.05252*20*u'

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Jul 2018
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 Comments
jose luis guillan suarez
jose luis guillan suarez on 12 Jul 2018
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
jose luis guillan suarez on 19 Jul 2018
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

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!