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]);
end
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.
Thank you.
댓글 수: 0
채택된 답변
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
Walter Roberson
2016년 4월 17일
I do not know what it stands for in terms of the equation, but v corresponds to the standard "y" parameter for the ode functions, so the [0 0] is the initial conditions for the initial time.
추가 답변 (2개)
Swathi Kulkarni
2020년 10월 12일
clear
clc
Patient='Sarah';
Temp=102.6;
SBP=138;
DBP=76;
Charge =35;
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!