Dimension mismatch for using Runge Kutta 4 order methods

조회 수: 4 (최근 30일)
Phong Pham
Phong Pham 2012년 8월 15일
No longer available
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 8월 15일
When you encounter the problem, what are the size() of k1, k2, k3, k4 ?
Walter Roberson
Walter Roberson 2012년 8월 16일
Please do not delete the content of questions after they are responded to. Content should only be removed if it is inappropriate for the forum (for example if it was not about MATLAB); otherwise it should be left for future reference.
Some of the volunteers get quite frustrated when people remove content that the volunteers have expended time and energy to answer; it makes them feel like their efforts were a waste of everyone's time, and that leads some of the volunteers to withdraw.

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

답변 (1개)

Kye Taylor
Kye Taylor 2012년 8월 15일
If dx/dt = [0,0,.4,0] for a vector x, then the exact solution is
x(t) = [x0, x1, 0.4*t+x2, x3]
where x0,x1,x2,x3 are initial conditions (position).
Is func really indepenent of t and x(i)?
The issue with your code is that func will return a row vector, but x(:,1) is intialized as a column vector. Then the right-hand-side defining x(:,2) is column vector plus row vector -- this produces an error.
It is because func seemingly returns a row vector, independent of its inputs size or value, that your code is actually working. Perhaps there is more to func?
  댓글 수: 1
Kye Taylor
Kye Taylor 2012년 8월 15일
You mean U = A\B, not U = A\B'...
Try replacing the x(i) in the for loop with x(i,:)

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by