필터 지우기
필터 지우기

Error in a ODE in a loop (returns a vector of length 9, but the length of initial conditions vector is 2)

조회 수: 2 (최근 30일)
Hi everybody, and thanks again for the help.
I run the file ciclo_1_bis, which loads from the file z_matlab_1 different vectors, and at every loop
it updates the initial condition, and other parameters stored in z_general_1.
First loop (j=1) ok, the when j=2 it says this erroor message:
Error using odearguments (line 92)
GREITZER returns a vector of length 9, but the length of initial conditions vector is 2. The vector returned by
GREITZER and the initial conditions vector must have the same number of elements.
Error in ode113 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
what could be possibily wrong? It just changes the initial conditions and the time for the next loop.

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 2일
When you
save main_parameters.mat
after the first loop, then the workspace includes the t that was the result of the [t,y] = ode113() call.
When you load() that .mat inside the function, that t gets pulled inside the workspace, replacing the t that was passed in as a function parameter.
Don't DO that. Do not save() and load() like that. Pass the values in to the function, either individually or as part of a structure. http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
  댓글 수: 14
Paul Rogers
Paul Rogers 2021년 2월 3일
편집: Paul Rogers 2021년 2월 3일
Walter Roberson thanks a lot, I re-wrote the code the way you told me.
I can't bellive how much I gained in speed! I weent froom almost 1h to a few seconds. Incredible, thanks again for your time.
Now I can focus on the algorythm.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by