Failure in initial objective function evaluation. FSOLVE cannot continue.

25 ビュー (過去 30 日間)
Matheus Rodrigues
Matheus Rodrigues 2018 年 2 月 5 日
コメント済み: Star Strider 2018 年 2 月 5 日
Hello, i'm trying to solve a nonlinear system of equations and I saw on the web that the function I should be looking for was "fsolve" (I am a beginner MATLAB user). I created my personal function as the following:
function y = eita(x, alpha)
y(1) = 1.543*10^-5 * x + 0.57
y(2) =(44.092 / 0.89605 - x) - alpha
end
Then I opened another path to call fsolve:
fun = @eita
x0= [0,0]
sol = fsolve(fun,x0)
But something is wrong with my code and I get this command box report:
Subscripted assignment dimension mismatch.
Error in eita (line 2)
y(1) = 1.543*10^-5 * x + 0.57
Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});
Error in ha (line 3)
sol = fsolve(fun,x0)
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

採用された回答

Star Strider
Star Strider 2018 年 2 月 5 日
You have to choose between coding them as:
function y = eita(x, alpha)
y(1) = 1.543E-5 * x + 0.57;
y(2) = (44.092 / 0.89605 - x) - alpha;
end
alpha = 3;
x0 = 1;
sol = fsolve(@(x)eita(x,alpha), x0)
to optimise ‘x’ with fixed ‘alpha’, or:
function y = eita(xv)
x = xv(1);
alpha = xv(2);
y(1) = 1.543E-5 * x + 0.57;
y(2) = (44.092 / 0.89605 - x) - alpha;
end
x0 = [1; 1];
sol = fsolve(@(x)eita(x), x0)
if you want to optimise both parameters.
  2 件のコメント
Matheus Rodrigues
Matheus Rodrigues 2018 年 2 月 5 日
It worked, thanks mate
Star Strider
Star Strider 2018 年 2 月 5 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by