Solve is not providing correct solution

조회 수: 3 (최근 30일)
NGiannis
NGiannis 2024년 3월 2일
댓글: Dyuman Joshi 2024년 3월 2일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by