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
  3 个评论
NGiannis
NGiannis 2024-3-2
Thanks for your reply.
The solution you provided make the "a-b*(k*Q)" and "a-(c-d)*k" zero. I need to use the "a-b*(k*Q)" and "a-(c-d)*k" also the individual numbers a, b, c, d, k on equations.
VBBV
VBBV 2024-3-2
编辑:VBBV 2024-3-2
Ok, check whether the following
a-b*(k*Q), a-(c-d)*k,
operations on a, b,c,d k, & Q are correct. Can you tell how they change the transfer function ? Is code called inside a loop with inputs to transfer function?

请先登录,再进行评论。

回答(1 个)

Dyuman Joshi
Dyuman Joshi 2024-3-2
When you use vpa on symbolic numbers, you lose precision.
When you convert the symbolic numbers to double precision values using double, you lose precision.
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
a = 
b = 
c = 
d = 
k = 
1
ans = 
0
ans = 
0
ans = 
  2 个评论
NGiannis
NGiannis 2024-3-2
Thanks you for your reply.
The solution you provided make the "a-b*(k*Q)" and "a-(c-d)*k" zero. I was using the double(subs(number)) in order to be able to use the values on s-domain. When appling the values on transfer funciton I am getting "Unable to convert tf to sym".
Dyuman Joshi
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.

请先登录,再进行评论。

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by