Solve is not providing correct solution
2 次查看(过去 30 天)
显示 更早的评论
I am trying to solve the below equation which is a part of a transfer function calculation.
clear
syms a b c d k
Hhf=6;
Q=3;
Coeff2=0;
Coeff3=0;
assume(a,["positive","real"]);
assume(b,["positive","real"]);
assume(c,["positive","real"]);
assume(d,["positive","real"]);
assume(k,["positive","real"]);
eq1=vpa(a==10^(Hhf/20))
eq2=vpa(a-b*(k*Q)==Coeff2)
eq3=vpa(a-(c-d)*k==Coeff3)
eq4=vpa(1+a+b+c==7.5)
[a,b,c,d,k]=solve([eq1,eq2,eq3,eq4], [a,b,c,d,k]);
a=double(subs(a));
b=double(subs(b));
c=double(subs(c));
d=double(subs(d));
k=double(subs(k));
a, b, c, d, k, a-b*(k*Q), a-(c-d)*k, 1+a+b+c
The output is below:
a = 1.9953
b = 0.6651
c = 3.8397
d = 1.8444
k = 1
a-b*(k*Q) = 2.2204e-16
a-(c-d)*k = -2.2204e-16
The "a-b*(k*Q)" and "a-(c-d)*k" are very smal numbers but are not zero as requested. These values when multiplied with others are changing the transfer function. Any idea how can be resolved.
Giannis
回答(1 个)
Dyuman Joshi
2024-3-2
And that's why the values are not exactly 0.
If you remove those conversions, the values will, in fact, be 0.
syms a b c d k
Hhf=6;
Q=3;
Coeff2=0;
Coeff3=0;
assume(a,["positive","real"]);
assume(b,["positive","real"]);
assume(c,["positive","real"]);
assume(d,["positive","real"]);
assume(k,["positive","real"]);
eq1=(a==10^(Hhf/20));
eq2=(a-b*(k*Q)==Coeff2);
eq3=(a-(c-d)*k==Coeff3);
eq4=(1+a+b+c==7.5);
[a,b,c,d,k]=solve([eq1,eq2,eq3,eq4], [a,b,c,d,k]);
a, b, c, d, k, a-b*(k*Q), a-(c-d)*k, 1+a+b+c
2 个评论
Dyuman Joshi
2024-3-2
Yes, Control system functionalities in MATLAB, like tf, do not accept symbolic numbers as input (this issue has been raised quite a few times by others as well).
I understand your situation, but unfortunately, you will have to work with the limited precision of double precision numbers, where the values are not exactly zero.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!