Solve is not providing correct solution
이전 댓글 표시
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
VBBV
2024년 3월 2일
use round function to make it zero and then use in the transfer function
double(round((a-b*(k*Q)),1));
double(round((a-(c-d)*k),1));
double(round((1+a+b+c),1));
NGiannis
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개)
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
NGiannis
2024년 3월 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.
카테고리
도움말 센터 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!