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

1 vue (au cours des 30 derniers jours)
Robert  Flores
Robert Flores le 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 commentaire
John D'Errico
John D'Errico le 6 Mai 2018
Modifié(e) : John D'Errico le 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.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by