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

Thank you so much! It worked perfectly!!
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2018년 1월 19일

댓글:

2018년 1월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by