iterate fsolve and save each iterated result

7 次查看(过去 30 天)
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 =)

采纳的回答

Walter Roberson
Walter Roberson 2013-3-26
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 个评论
Walter Roberson
Walter Roberson 2013-3-28
The starting guess for iteration #n will be the output from iteration #(n-1)
MEXICO
MEXICO 2013-3-28
i have this
for n = 2:k;
ua(1)=uamin;
ua(n) =ua(n-1)+dua;
[x((n-1),:)] = fsolve(@(x) func(x,ua(n-1)), x0, options)
x0 = x((n-1),:);
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by