fsolve with a changing variable using a for loop

1 view (last 30 days)
I know this is wrong, but I don't have any idea how to do it. Trying to solve for x at each of the different points of u. I want to output an array of answers that correspond.
u is a 10143x1 array.
for i = 1:10143
fun(i) = @(x) -(h^2-2*h*x+x^2)*(0.04)-(1025*u(i)^2*x)/g;
y(i) = fsolve(fun,-75);
end

Answers (1)

Walter Roberson
Walter Roberson on 11 Dec 2019
syms h x U g
sol = solve(-(h^2-2*h*x+x^2)*(0.04)-(1025*U^2*x)/g,x);
y = subs(sol, U, u(:).');
As you are looking for negative values, your desired solution will be y(1,:) if g is positive,and y(2,:) if g is negative.
Note: the solutions are complex outside of u in the interval +/- 2/1025 * sqrt(41) * sqrt(g*h)

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!