iterate fsolve and save each iterated result

6 ビュー (過去 30 日間)
MEXICO
MEXICO 2013 年 3 月 25 日
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 Center および File ExchangeSolver 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