Solve system of nonlinear equations without symbolic variables
조회 수: 12 (최근 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!