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

조회 수: 2 (최근 30일)
Robert  Flores
Robert Flores 2018년 5월 6일
편집: John D'Errico 2018년 5월 6일
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