Suppose I have 10 equations and 10 unknowns. In the equations there are 10 constants that I don’t optimize, say C1,C2,…C10.
Is there a way to use Fsolve and Loops to solve my equations if I have 5 different sets of constants ( 5 times C1,C2,…C10) that satisfy my original 10 equations. Simply put, instead of rewriting my 10 equations and 10 unknowns… 5 times by hand, is there a way to loop inside the @myfun m-file I wrote to solve for my 10 unknowns?
Use anonymous functions, available in MATLAB since R14 I believe.
From fsolve help:
If FUN is parameterized, you can use anonymous functions to capture the problem-dependent parameters. Suppose you want to solve the system of nonlinear equations given in the function myfun, which is parameterized by its second argument c. Here myfun is an M-file function such as
function
使用Matlab fsolve与循环解决参数化方程组

本文探讨如何在Matlab中利用fsolve函数和循环处理包含常数参数的非线性方程组。当有多个不同常数集(如C1到C10的5种组合)时,而不是手动多次重写方程,可以尝试在自定义函数@myfun内实现循环,以此求解10个未知数。示例中建议使用匿名函数来捕获问题的参数,通过将特定的c值赋给参数,创建一个一元匿名函数调用myfun,并将此匿名函数传递给fsolve。
最低0.47元/天 解锁文章
363

被折叠的 条评论
为什么被折叠?



