Function as sum of functions in fsolve
3 次查看(过去 30 天)
显示 更早的评论
I want to solve a set of nonlinear equations over two unknowns x(1) & x(2), e.g. in the form:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162087/image.png)
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!