How to solve for each value a SOLVE equation

1 view (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 19 Jan 2018
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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!