iterate fsolve and save each iterated result
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hi every body. im using fsolve to solve 3x3 non linear system. i have a parameter (velocity) that i want to encrease every time i solve the 3x3 system. my question is, how i iterate fsolve and how i save the results. i have this main file that call the fsolve
clc
clear all
basico;
uo2=1;
yo2=0.1;
yo3=0.1;
x0 = [uo2; yo2; yo3]; % Make a starting guess at the solution
options=optimset('Display','iter');% Option to display output
[x,fval] = fsolve(@func,x0,options) % Call solver
so every time i solve the system i get a vector x with 3 values solved by fsolve. i want to iterate FSOLVE and in each iteration increase a parameter inside FUNC file and save the results for plot it.
any idea? thanks for advance =)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Mär. 2013
options=optimset('Display','iter');% Option to display output
x0 = [uo2; yo2; yo3]; % Make a starting guess at the solution
maxiter = 1000; %however many
x = zeros(1, maxiter);
fval = zeros(1, maxiter);
for ITER = 1 : maxiter %however many
newparam = revise_parameter(ITER, maxiter); %a function to return the revised parameter
[x(ITER), fval(ITER)] = fsolve(@(x) func(x, newparam), x0, options);
x0 = x(ITER);
end
plot(x, fval);
This would involve adding the "parameter inside FUNC file" as an argument to func, and would involve creating a new function revise_parameter that accepts the current iteration number and maximum iteration limit and returns the value that you would otherwise have revised the "parameter inside FUNC file" to.
5 Kommentare
Walter Roberson
am 28 Mär. 2013
The starting guess for iteration #n will be the output from iteration #(n-1)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!