How to solve for a variable when equation is equal to a constant?

2 次查看(过去 30 天)
Hello,
I am trying to solve for L in my code, however it either takes to long to run or outputs an error. The commented out section is when the code takes to long to run. The new lines of code spits out an error. If you can help me, it would be most appreciated.
CODE:
%% L calculation
close all, clear, clc
m = 100;
g = 9.81;
syms L
K = (2*m*g*(2*(L-10)+90))/((L-10)+90)^2;
x_dot = sqrt(2*g*(L-10));
wn = sqrt(K/m);
phi = atan(x0*wn/x_dot);
t = sqrt(2*(L-10)/g);
eqn = wn*t+phi;
solve(eqn,L)
%l = L-10;
% syms L
% eqn = ((((3924*(L-10)+176580)/((L-10)^2+180*(L-10)+8100))/100)^0.5)*(sqrt((2*(L-10))/g))+atan(((((981)/(3924*(L-10)+176580))/((L-10)^2+180*(L-10)+8100))*(((3924*(L-10)+176580)/((L-10)^2+180*(L-10)+8100))/100)^0.5)/sqrt(2*g*(L-10))) == (pi/2);
% solx = solve(eqn,L)
  1 个评论
John D'Errico
John D'Errico 2018-5-6
编辑:John D'Errico 2018-5-6
People for some reason think that if you don't know the value of a parameter, it MUST be left as symbolic, and then use solve.
You don't need to do that. The result here will be a purely numerical root. If you think you need high precision afforded by the symbolic toolbox, then you don't have enough digits in your numbers anyway.
Just use fzero. Put all that code into one function, with L as an input. Then call fzero on the function to find the root.
By the way, we cannot look at what you have here, because you never provided the value of X0.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by