Solve system of nonlinear equations without symbolic variables
23 次查看(过去 30 天)
显示 更早的评论
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]);
0 个评论
采纳的回答
John D'Errico
2017-6-19
编辑:John D'Errico
2017-6-19
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!