How to solve for each value a SOLVE equation

Qout is a line matrix [1*cont] and I want to obtain a solution for x for each Qout and to store that information in some new matrix. How can I do this? Thank you very much!
x = [];
for i=1:1:cont
eqn = @(x) Qout(i) == Ks*(d^2 * (2*x - sin(2*x)) / 8)*((d * (1 - sin(2*x) / 2*x) / 4)^(2/3))*sqrt(s) ;
solve(eqn,x)
x1(i)=x
end
when I run the code above I get a error message:
Error using solve>getEqns (line 414)
The input contains an empty equation or variable.
Error in solve (line 225)
[eqns,vars,options] = getEqns(varargin{:});
Error in Ficha3_1 (line 112)
solve(eqn,x)
Sorry if it's missing information but I'm quite noob at this.

 採用された回答

Star Strider
Star Strider 2018 年 1 月 19 日

0 投票

I would not use the Symbolic Math Toolbox for this, and use the Optimization Toolbox fsolve function or the core MATLAB function fzero instead.
Try this:
x0 = 1;
x1 = nan(1,cont);
for i=1:1:cont
eqn = @(x) Qout(i) - ( Ks*(d^2 * (2*x - sin(2*x)) / 8)*((d * (1 - sin(2*x) / 2*x) / 4)^(2/3))*sqrt(s) );
x1(i) fsolve(eqn, x0);
end
Note There are an infinity of solutions because ‘x’ is an argument to the sin() function. This example code will only find the solution closest to the initial estimate ‘x0’ in each iteration of the loop.

2 件のコメント

Rebeca Marini
Rebeca Marini 2018 年 1 月 22 日
Thank you so much! It worked perfectly!!
Star Strider
Star Strider 2018 年 1 月 22 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by