using gradient with ode45
古いコメントを表示
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
2018 年 7 月 7 日
Can you post the question to solve?
jose luis guillan suarez
2018 年 7 月 7 日
編集済み: Walter Roberson
2018 年 7 月 7 日
回答 (1 件)
Walter Roberson
2018 年 7 月 7 日
0 投票
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
2018 年 7 月 8 日
Walter Roberson
2018 年 7 月 9 日
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
2018 年 7 月 10 日
Walter Roberson
2018 年 7 月 10 日
> 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
2018 年 7 月 11 日
Walter Roberson
2018 年 7 月 11 日
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
2018 年 7 月 12 日
jose luis guillan suarez
2018 年 7 月 19 日
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

