Solving dependent functions using ODE45
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi All,
I am trying to solve a set of equations that are dependent on each other. dx_dt(1) is dependent on dx_dt(2). dx_dt(2) and dx_dt(3) are dependent on dx_dt(1). I have not been able to solve this. Any suggestions are greatly appreciated.
採用された回答
Star Strider
2016 年 6 月 24 日
The ode45 and other functions (choosing the appropriate solver is important) are able to solve such systems of differential equations relatively easily. Please post your code for your differential equation funciton, and original equations if necessary.
5 件のコメント
Thanks for the help. My ODE code is below. When I run the original code, I get an error in my dynamics file. The error is "Undefined function 'vLp1'".
*Note* vLp1 = dx_dt(2,:) vL = dx_dt(1,:)
function dx_dt = dyn(t,x,params)
global Vs D fsw L C C2 Rload rL Lp1 Lp2 Cj1 Cj2;
iL = x(1);
iLp1 = x(2);
iLp2 = x(3);
vC = x(4);
vj1 = x(5);
vj2 = x(6);
dtri = x(7);
d = D;
tri = dtri + 0.5;
if (d >= tri)
x = 0;
y = 1;
else
x = 1;
y = 0;
end
vrL = rL*iL;
iLoad = vC/Rload;
dx_dt(1,:) = (x*(Vs - vC) + y*(-vj1 - vLp1 - vC))/L;
dx_dt(2,:) = (x*(-Vs - vj1) + y*(-vj1 - vL - vC))/Lp1;
dx_dt(3,:) = (x*(-Vs - vj2) + y*(-vj2 - vL -vC))/Lp2;
dx_dt(4,:) = (iL - iLoad)/C;
dx_dt(5,:) = (iLp1 - iD1)/Cj1;
dx_dt(6,:) = (iLp2 - iD2)/Cj2;
dx_dt(7,:) = 2*fsw*sign(cos(2*pi*fsw*t));
Star Strider
2016 年 6 月 27 日
My pleasure.
Do not use globals! They cause the problems you’re seeing, because you cannot control them and they make debugging your code almost impossible. I don’t know what the ‘params’ argument refers to, since you never use it in your code.
I would do this instead:
function dx_dt = dyn(t,x, Vs, D, fsw, L, C, C2, Rload, rL, Lp1, Lp2, Cj1, Cj2)
and delete the global call.
I don’t understand what you’re doing in the if block, but be aware that the ODE solvers do not handle integrating across discontinuities at all well (No numerical solvers do.) The same caution applies to:
dx_dt(7,:) = 2*fsw*sign(cos(2*pi*fsw*t));
although if the magnitude of ‘dx_dt(7,:)’ isn’t large, especially with respect to the other values, the effect of the discontinuity may not be significant.
I thought I was being clever using globals. I'll scratch that off of my to-do list and stay away from them. I've added them like you suggested above.
I am still having the same problem though. I changed my code as shown below. Looking at the previous code I posted, vLp1 definitely wasn't defined. I noted what it was in my post, but it was not in my actual code. Below is what I have now. I am getting the same error, "Undefined function or variable dxdt".
Also, with the sign function, I'm creating a triangle wave. Basically, I'm doing PWM with a triangle wave with magnitude 1.
Star Strider
2016 年 6 月 28 日
The use of global variables is a remnant of earlier computer languages (like FORTRAN II that I learned programming with back in 1968) when that was the only way to pass variables and avoid some restrictions on subroutine (MATLAB function) usage. They are vestigial, and will eventually disappear. They are definitely to be avoided in MATLAB code.
One other problem you mentioned in a subsequent Question was that ‘dxdt(1)’ requires ‘dxdt(2)’. I would eliminate the double subscripts (that could be part of the problem), and instead insert a line defining ‘dxdt’ as a column vector from the outset:
...
iLoad = vC/Rload;
dxdt = zeros(7,1);
dxdt(1) = (x*(Vs - vC) + y*(-vj1 - Lp1*dxdt(2) - vC))/L; % diL/dt
...
and so for the others. I’m not certain that will solve your problem, since I didn’t run your code, but it should at least eliminate the problem you mentioned.
Torsten
2016 年 6 月 29 日
@Josh:
Take the first and the second equation (dxdt(1,:) = ... and
dxdt(2,:) = ...) and solve for dxdt(1) and dxdt(2) (2 linear equations in two unknowns).
Alternatively, use the mass-matrix option of the ODE integrators.
Best wishes
Torsten.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
