Solving dependent functions using ODE45
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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));
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.
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.
@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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
