how to solve error "Error using sym/min"? in my code

2 views (last 30 days)
my code :
format long
sprintf('%16.f',2332456943534324);
l=30;
L=300;
m=10^6;
g=9.81;
M=556594.32;
k1=2.0201*10^12;
c1=9.769*10^10;
c2=0;
s=2i;
sym k2;
a0=(k1*(m*g*L+k2)-(m*g*L*(m+M)+k2*M)*g*L)/(m*(M*L*l)^2);
a1=(c1*(m*g*L+k2)+c2*(k1-M*g*L))/(m*(M*L*l)^2);
a2=(c1*c2+m*M*g*L*(L^2-l^2)+k1*m*l^2+k2*m*(L-l)^2+k2*M*L^2)/(m*(M*L*l)^2);
a3=(c1*(l^2)*m+c2*m*(L-l)^2+c2*(L^2)*M)/(m*(M*L*l)^2);
G1=-(s^2+c2*s/m*(l^2)+(m*g*L+k2)/(m*(l^2)))/((M*L)*((s^4)+(s^3)*a3+(s^2)*a2+(s)*a1+a0));
mag=abs(G1);
[ym,ind]=min(mag);
---------------
the error:
Error using sym/min (line 123)
Input arguments must be convertible to floating-point numbers.
-------------------------------------
i have no idea how to fix so i can find the index of the minimum

Answers (1)

Walter Roberson
Walter Roberson on 29 May 2019
You need
syms k2;
instead of
sym k2;
But your main problem is that mag is an expression with a symbolic variable, and you cannot use min() on an expression with an unresolved symbolic variable.
To find the k2 that minimizes mag, you can observe that abs() is never negative, so if there is a value of k2 that makes mag 0 then that is a minima. So examine mag and observe that it has
abs(k2/900000000 - 73/100)
divided by something.
>> solve(k2/900000000 - 73/100)
ans =
657000000
and this will be a minima, yielding 0.
You can also find the maximum.
solve(diff(mag,k2),k2)
and the maxima will be at the value that is not 657000000 . It turns out that you get the same maxima at k2 = -inf

Community Treasure Hunt

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

Start Hunting!