Please find the fault in the mentioned code
1 ビュー (過去 30 日間)
% code for solving a non-linear non-inhomogeneous(pulse I/P, U) ODE system %
syms t v u
g=@(t,v,u)[-((1.17*10^-6) + (9*10^-3*t^-0.5))*v(1) + (9*10^-3*(t^-0.5))*v(2) + 0.12*u; (9*10^-3*t^-0.5)*v(1) - (9*10^-3*t^-0.5)*v(2) + (5.8*10^-3)*u];
for u=[0 4 4 4 4 0 0 0 0 0]
[t,va] = ode45(@(t,v) g(t,v,u),[0 10],[0 0]);
That code always gives the ans NaN, which should not be. Any one can tell me where is the fault actually? And how to plot the output for the whole input (U)?
Used Matlab version is 2013a.
Walter Roberson 2016 年 4 月 17 日
You have t^-0.5 in several places. That is going to give inf at t = 0. The subterms that give infinity are multiplied by v(1) or v(2), both of which start at 0, and inf * 0 is NaN.
You can change your initial conditions to both be non-zero so that the inf is not being multiplied by 0 and so will not give rise to NaN. If you do that for t = 0, then it so happens that the sub expressions (9*10^-3*t^-0.5))*v(1) and (9*10^-3*(t^-0.5))*v(2) give infinities with opposite sign, one +inf and the other -inf . +inf + -inf is also NaN . Therefore you cannot just fix this by changing your initial conditions to be non-zero.
You can change your initial time to be greater than 0 so that the inf does not occur. That will not lead to any computation problems. You would, however, then discover that if your initial conditions for v are both 0, that the integral will stay 0.
その他の回答 (2 件)
Swathi Kulkarni 2020 年 10 月 12 日
fprintf('Sarah had a temperature of %4.1f and a blood pressure of %d / %d.\n The Charge for this visit is $%d.\n',Patient,Temp,SBP,DBP,Charge)
please tell me the fault in the code
The ouput should display Sarah had a temperature of102.6 and a blood pressure of 138/76.
The charge for this visit is $35.