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.
Walter Roberson
Walter Roberson 2021 年 2 月 3 日
File I/O is a lot slower than computation, except sometimes to SSD.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops 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