Runtime Errors: MatLab Optimisation
Mostra commenti meno recenti
Hi everyone! I am trying to run an optimisation problem using fmincon which involves numerically solving an associated system of differential equations as in the code attached. Currently, running the code returns a few errors that I can't figure out. These are the errors that the compiler prompts:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in newcrime>myode (line 74)
K1 = K(:,1:N);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in newcrime (line 38)
[t,z] = ode15s(@myode, [0,tf], z1, opts, K);
I have pursued some options with changing function parameters and redefining local paramters within the functions, all to no avail. Any help would be really appreciated! Thank you!
Risposte (1)
Walter Roberson
il 6 Mag 2019
0 voti
The line of code giving the error in the error message does not exist inside the code that you have posted.
The code that you have posted appears to use K correctly. You build a row vector x, use it to calculate some values, and use .' to transpose that into a column vector, and you put two of those together into a column vector, so K is a single column vector. It is incorrect to try to access multiple columns of it.
You should not be using that syntax to pass K into the ode function. See http://www.mathworks.com/help/matlab/math/parameterizing-functions.html showing how to pass it in through the function handle.
1 Commento
Tarun Yadav
il 6 Mag 2019
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!