Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 2 Feb 2021
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 Commenti
Paul Rogers
Paul Rogers il 3 Feb 2021
Modificato: Paul Rogers il 3 Feb 2021
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by