Evaluating constants
Afficher commentaires plus anciens
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?
1 commentaire
Jan
le 27 Déc 2011
The interesting part of the error message is missing...
Réponse acceptée
Plus de réponses (1)
John D'Errico
le 27 Déc 2011
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.
Catégories
En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!