Evaluating constants
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I have to evaluate a very complicated number, and its important to me, so i can not use calculator to find because the accuracy will decrease, so I wrote the following code:
gm1 = 0.01;
gm2 = 0.01;
gm4 = 0.04;
gm5 = 0.04;
gm7 = 0.04;
gm8 = 0.2;
re1 = 99;
re2 = 99;
re4 = 24.75;
re5 = 24.75;
re7 = 24.75;
re8 = 4.95;
ro1 = 400e3;
ro2 = 400e3;
ro4 = 100e3;
ro5 = 100e3;
ro8 = 20e3;
R1 = 20e3;
R2 = 20e3;
R3 = 3e3;
R4 = 2.3e3;
R5 = 15.7e3;
R6 = 3e3;
P1 = (R1*ro1)/(R1 + ro1);
P2 = (R2*ro2)/(R2 + ro2);
P3 = (R3*ro5)/(R3 + ro5);
P4 = (R6*ro8)/(R6 + ro8);
K1 = 101*(re8 + P4);
K2 = 101*(re7 + R4);
K3 = 101*(re5 + re4);
K4 = 101*(re1 + re2);
ANS2 = (P4/K4)*101*(100^3)*(R5/(R5+K1))*(P3/(P3+K2))*((P2+P1)/(P1+P2+K3));
as you can see, it is very complicated, now you can see that I will get the error " ??? Undefined function or variable" for all these constant.. so what should i do?
채택된 답변
Jan
2011년 12월 27일
The posted code is working without an error. Matlab#s MLint mentions, that ro4 and all gm* variables are not used. But I do get an error message.
What about this:
ANS2 = 8010.837753694346;
Another impression: The accuracy of the output depends on the accuracy of the inputs. Did you analyse the sensitivity of the output to a variation of the inputs already? If accuracy matters, such an analysis is fundamental.
댓글 수: 1
추가 답변 (1개)
John D'Errico
2011년 12월 27일
Well, if you insist on accuracy...
DefaultNumberOfDigits 100 session
gm1 = hpf('0.01');
gm2 = hpf('0.01');
gm4 = hpf('0.04');
gm5 = hpf('0.04');
gm7 = hpf('0.04');
gm8 = hpf('0.2');
re1 = hpf('99');
re2 = hpf('99');
re4 = hpf('24.75');
re5 = hpf('24.75');
re7 = hpf('24.75');
re8 = hpf('4.95');
ro1 = hpf('400e3');
ro2 = hpf('400e3');
ro4 = hpf('100e3');
ro5 = hpf('100e3');
ro8 = hpf('20e3');
R1 = hpf('20e3');
R2 = hpf('20e3');
R3 = hpf('3e3');
R4 = hpf('2.3e3');
R5 = hpf('15.7e3');
R6 = hpf('3e3');
P1 = (R1*ro1)/(R1 + ro1);
P2 = (R2*ro2)/(R2 + ro2);
P3 = (R3*ro5)/(R3 + ro5);
P4 = (R6*ro8)/(R6 + ro8);
K1 = 101*(re8 + P4);
K2 = 101*(re7 + R4);
K3 = 101*(re5 + re4);
K4 = 101*(re1 + re2);
ANS2 = (P4/K4)*101*(100^3)*(R5/(R5+K1))*(P3/(P3+K2))*((P2+P1)/(P1+P2+K3))
ANS2 =
8010.837753694344316448807496109772836067535423597352814811877939938344594879856582655844910993168092
Yes, its a waste of digits. But in any event, nary an error generated as a double or a high precision float.
My guess is you have not shown us what your real (complete) code looks like.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!