Ode45 g and dg

조회 수: 2 (최근 30일)
Elahe S
Elahe S 2024년 10월 13일
댓글: Walter Roberson 2024년 10월 13일
For solving the equation dg2, dg6 is needed. Therefore the following error is shown:
Undefined function or variable 'dg4'.
How can it be fixed?
options = odeset('RelTol',1e-5,'AbsTol',1e-5);
[t,g] = ode45(@2system(t,g,t1,A, m, k)
function dg=2system(t,g,t1,A, m, k)
A1 = interp1(t1,A1x,t); % Interpolate the data set (t1,A1x) at time t
dg1=g(2);
dg2=m*A+k*g(1)+h1*k*g(3)+dg4
dg3=g(4);
dg4=h1*k2x*g(1)+dg2
dg=[dg1;dg2;dg3;dg4];
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 10월 13일
[t,g] = ode45(@2system(t,g,t1,A, m, k)
is invalid syntax.
function dg=2system(t,g,t1,A, m, k)
That is an invalid function name. Function names must begin with an upper or lower case Latin letter.

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2024년 10월 13일
편집: John D'Errico 2024년 10월 13일
You cannot use the variable dg4, before it is defined. And we see you do this:
dg2=m*A+k*g(1)+h1*k*g(3)+dg4
...
dg4=h1*k2x*g(1)+dg2
You use dg4 to define dg2, but dg4 does not exist at that time. And in fact, you then use dg2 to define the value of dg4 later on.
It might seem this just forces us to solve the linear system of equatinos, for the two unknowns dg2 and dg4. Well, CAN you solve the 2x2 linear system of equations to solve for those two values? Well, it might seem to be the case, but in fact, that linear system of equations is singular.
That singularity tells me that unless a very specific scenario exists, no solution is ever possible. Why not? Add the two equations together.
dg2=m*A+k*g(1)+h1*k*g(3)+dg4
plus...
dg4=h1*k2x*g(1)+dg2
Which yields:
dg2 + dg4 = m*A+k*g(1)+h1*k*g(3) + dg4 + h1*k2x*g(1) + dg2
Note that we have dg2 + dg4 on both sides of the equation. Drop them. Toss them in the bit bucket of mathematics. What remains tells us that:
m*A + k*g(1) + h1*k*g(3) + h1*k2x*g(1) == 0
So unless that expression is identically equal to zero, then NO solution exsts for dg2 and dg4.
And IF it is true that the above expression does equal zero, IDENTICALLY, then we have the scenario where you can choose any completely arbitrary value for dg4, and dg2 will be exactly dg4.
I'm sorry, but that is how mathematics works. In any case, your equations do not result in anything useful. They cannot do so, because either dg2 and dg4 do not exist, or they are completely arbitrary. Since neither case is acceptable, you need to return and look far more carefully at your equations.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by