Calculation giving me complex numbers exen though it shlouldn't
Show older comments
Hi.
I have the following code:
%angle in degrees
alpha = [28.8 41.4 68.4 90 117 126 133];
%angle in radians
alpha1 = (alpha./180).*pi;
%calculation:
I_RMS = 947.5 .* sqrt( (2./pi ).*( pi - cos( pi ).*sin( pi ) - alpha1 + cos( alpha1 ).*sin( alpha1 ) )./2 );
EDIT: the above code doesn't deliver complex numbers after all (I had retyped it to shorten my question): Here is exactly what I am trying to do (I have also changed the model-function so it's easier to read):
alpha1g = [28.8 41.4 68.4 90 117 126 133];
alpha1 = (alpha1g./180).*pi;
Ieff1 = [930 920 820 660 400 350 270];
%preparation for nlinfit:
Modelfun1 = @(I01,xx)(I01(1).*sqrt((1/pi).*(pi-xx+cos(xx).*sin(xx))));
I01 = 947.5;
I02 = 947.5;
I03 = 800;
%create fit
TI1 = nlinfit(alpha1, Ieff1, Modelfun1, I01);
alpha = linspace(0,pi,50000);
Trend1 = Modelfun1(TI1, alpha);
alpha = linspace(0,180,50000);
%plot original scatter and fit over alpha
scatter(alpha1g, Ieff1, 'r', 'filled'); hold on
plot(Trend1, alpha, 'r', 'LineWidth', 1.5);
This returns the message:
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In LE_TRIAC at 52
The fitted plot does not fit at all.
12 Comments
Azzi Abdelmalek
on 14 Nov 2013
I'am not getting complex numbers
Roger Stafford
on 14 Nov 2013
That expression of yours looks decidedly fishy. Why have you included sin(pi) which is zero? Why have you multiplied by 2 and later divided by 2 in the argument for 'sqrt'? Perhaps you actually gave matlab a slightly different expression.
Walter Roberson
on 14 Nov 2013
Is there a reason for taking cos(pi)*sin(pi) ? You know the result is going to be 0.
Marc Jakobi
on 14 Nov 2013
Marc Jakobi
on 14 Nov 2013
Edited: Marc Jakobi
on 14 Nov 2013
Walter Roberson
on 14 Nov 2013
You mean as in cos(alpha)+1 ?
Image Analyst
on 14 Nov 2013
There are sind() and cosd() versions of the functions that work directly in degrees you know.
Marc Jakobi
on 14 Nov 2013
Walter Roberson
on 14 Nov 2013
What value shows up for TI1 ?
Marc Jakobi
on 15 Nov 2013
Alfonso Nieto-Castanon
on 15 Nov 2013
Edited: Alfonso Nieto-Castanon
on 15 Nov 2013
that's probably just a rounding error (sin(pi) is not exactly 0), switching to sind & cosd should get rid of the imaginary parts (sind(180) IS exactly 0)... and I believe you want to use plot(alpha, Trend1, ...), not plot(Trend1, alpha, ...)
Marc Jakobi
on 15 Nov 2013
Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!