using gradient with ode45
Afficher commentaires plus anciens
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 commentaires
madhan ravi
le 7 Juil 2018
Can you post the question to solve?
jose luis guillan suarez
le 7 Juil 2018
Modifié(e) : Walter Roberson
le 7 Juil 2018
Réponses (1)
Walter Roberson
le 7 Juil 2018
0 votes
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 commentaires
jose luis guillan suarez
le 8 Juil 2018
Walter Roberson
le 9 Juil 2018
When you use ode45, the [0 10] tells it that it needs to integrate from t = 0 to t = 10. It will use variable time steps to do so, and it will report at whatever times it wants as long as the first is 0 and the last is 10. If you had specified something like linspace(0,10,101) then it would report with respect to 0:.1:10 but it would still calculate for whatever times it wants.
ode45 is not a fixed timestep solver.
ode45 calls the function you provide with a scalar time, and with a vector of boundary conditions that is the same length as your initial condition. It does not pass all of the times in a single call, because the boundary conditions (x) evolve with time.
jose luis guillan suarez
le 10 Juil 2018
Walter Roberson
le 10 Juil 2018
> diff(Vp*sin(2*Pi*t)+5, t);
2 Vp Pi cos(2 Pi t)
so if you want u' at time t, then use
2 * pi * Vp * cos(2 * pi * t)
jose luis guillan suarez
le 11 Juil 2018
Walter Roberson
le 11 Juil 2018
The derivative is 0 except at the integers, and it is undefined at the integers because square() is discontinuous. There are no rising or falling edges for a mathematical square wave.
There are approximations to square waves for which it is meaningful to ask about the derivative. http://mathworld.wolfram.com/FourierSeriesSquareWave.html
jose luis guillan suarez
le 12 Juil 2018
jose luis guillan suarez
le 19 Juil 2018
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

