Hello,
I need to do a complex calculation with numerous constants that may change regarding initial conditions. To do so, I decided to separate the arithmetic form (Pi5) from these constants, and put them into a matrix (A5). But it returns a complex results
With tests, I identified the problem as shown below in the code. The complex result (B_matrix) comes out when I raise a matrix component to power -1.2895 (result from 'A_matrix').
The calculation using numerical values has the right answer. But the same calculation using matrix components (A5(3) and A_matrix) gives a complex result.
Can somebody explain me what is the difference between the two cases please ? How can I change my code to still use the matrix and have a non-complex result ?
hmax=862.65e-9;hr = 814.23e-9;A5=[1.61217; 1.13111; -1.74756; -1.49291; 2.535334; -0.075187; 1.135865];Pi5= A5(1) * ( A5(2) + A5(3) ^ ( A5(4) .*((hr/hmax) . ^ (A5(5)))) + ... A5(6) .* (hr/hmax) .^ A5(7) );% Test 1 : A5(4).*( (hr/hmax).^(A5(5))
A_num= (-1.49291*(hr/hmax)^2.535334)A_matrix = (A5(4)*((hr/hmax).^(A5(5))))%Test 2 : A5(3)^( A5(4).*( (hr/hmax).^(A5(5)) )
B_num= -1.74756^(-1.49291*(hr/hmax)^2.535334)B_matrix =A5(3)^A_matrix
Command Window
A_num =
-1.2895
A_matrix =
-1.2895
B_num =
-0.4868
B_matrix =
-0.2990 + 0.3842i
Best Answer