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
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 Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!