Solve system of nonlinear equations without symbolic variables

26 views (last 30 days)
Is there a way to solve a system of 3 nonlinear equations without symbolic variables? I showed how to solve the equations I need solved below using solve() but is there a way to do it without symbolic variables?
syms u dt u_z
hf = 0;
u0 = 16;
Alt = 69.96;
dz = hf - Alt;
a = 2;
theta = 35;
phi = 10;
ax = a*cosd(theta)*cosd(phi);
ay = a*sind(theta)*cosd(phi);
az = a*sind(phi) - 9.8;
f1 = 0 == u0 + a*dt - u;
f2 = 0 == u*sind(phi) - u_z;
f3 = 0 == (u_z - sqrt(2*az*dz + u_z^2)/az) - dt;
[u, u_z, dt] = solve([f1, f2, f3], [u, u_z, dt]);

Accepted Answer

John D'Errico
John D'Errico on 19 Jun 2017
Edited: John D'Errico on 19 Jun 2017
Just create a function, then use fsolve from the optimization toolbox. There is no reason to use symbolic variables in that case. Often people think they need to create symbolic variables. A function handle is sufficient.
I think too often people assume they need to use symbolic variables, just because they don't know the value of a variable. For example, solve the problem:
f(x) = x^2 - 2 == 0
Of course, we know the answer is x = +/- sqrt(2), and the symbolic toolbox will tell us that. So we might define x as symbolic. Then define f as x^2-2, and use solve on f.
Instead, define a function handle,
f = @(x) x.^2-2;
Now just call a rootfinder (fzero) or for problems with multiple variables, fsolve. You will get a numerical result, thus 1.41421..., accurate to some number of digits.
There are good examples of the use of fzero & fsolve in the documentation, so I'm not going to retype that.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!