Function as sum of functions in fsolve

1 回表示 (過去 30 日間)
Saeid
Saeid 2017 年 3 月 23 日
コメント済み: Walter Roberson 2017 年 3 月 23 日
I want to solve a set of nonlinear equations over two unknowns x(1) & x(2), e.g. in the form:
where factors a(i), b(i), k(j) and m(j) are known. I am not aware of how I can define the function: fun= @ (x) in a loop. Some help here would be really appreciated! Saeid

採用された回答

Matt J
Matt J 2017 年 3 月 23 日
Just like you would without a loop. I assume you mean a loop over j...
asum=sum(a);
bsum=sum(b);
for j=1:length(k)
fun=@(x) myfun(x,asum,bsum,m(j),k(j));
xsol(j)=fsolve(fun,...)
end
function F=myfun(x, asum,bsum, mj,kj)
x1=x(1); x2=x(2);
F=[asum*x1^2+bsum*x1*x2^2 - kj ; you_fill_in_the_rest]
end
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 3 月 23 日
I like the optimization of moving the asum and bsum out of the loop.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by