iterate fsolve and save each iterated result

조회 수: 7 (최근 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 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