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

1 Ansicht (letzte 30 Tage)
Robert  Flores
Robert Flores am 6 Mai 2018
Bearbeitet: John D'Errico am 6 Mai 2018
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 Kommentar
John D'Errico
John D'Errico am 6 Mai 2018
Bearbeitet: John D'Errico am 6 Mai 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by