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!

