Complex answer of acos function
Mostra commenti meno recenti
Hello,
in my programm I'm using the following function:
function t1 = t1_function(u_a0,u_cs0,u_e,l,cs,cp)
t1 = (1/(realsqrt((1/(l*cs))+(1/(l*cp)))))*acos(1-(2*u_a0*(1+(cp/cs))/(u_e+u_a0-u_cs0)));
end
The goal is to use different values of u_e, u_a0 and u_cs0 and get the time value t1.
I know that the acos function acos(x) will output a complex answer if the value of x is not between -1 and 1. So in the main file I sorted all the values for u_e, u_a0 and u_cs0 out where the inside of the acos bracket gets out of range.
% Constants
C_s = 390e-12;
C_p = 251e-12;
C_A = 28e-9;
L = 370e-6;
R_Last = 400;
I_Last = 0;
% For Input Value
q_Array = [400 0 -400];
% For saving data
i=1;
u_e_Array = [];
u_cs0_Array = [];
u_A0_Array = [];
t1_Array = [];
for a=1:1:3
u_e = q_Array(a);
for u_A0 = 0:10:400
for u_cs0 = -1500:10:1500
x = 1-(2*u_A0*(1+(C_p/C_s))/(u_e+u_A0-u_cs0)); % Here I make sure that the Value inside the acos bracket
% stays between -1 and 1
if (x > -1) && (x < 1)
u_e_Array(i) = u_e;
u_cs0_Array(i) = u_cs0;
u_A0_Array(i) = u_A0;
t1 = t1_function(u_A0,u_cs0,u_e,L,C_s,C_p);
t1_Array(i) = t1;
i = i+1;
end
end
end
end
Even though I checked the values of x for each iteration and it stayed in between -1 and 1, Matlab calculates a complex value for t1. Can anybody explain to me why?
Risposta accettata
Più risposte (1)
Sulaymon Eshkabilov
il 7 Set 2020
0 voti
Hi,
It has been checked and your script is not giving ' complex' values for t1 or t1_Array. It is working ok.
Good luck
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!