Calculation giving me complex numbers exen though it shlouldn't

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

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.
Is there a reason for taking cos(pi)*sin(pi) ? You know the result is going to be 0.
No, not really. I just integrated sin²(x) from alpha to pi and multiplied it with 2/pi then took the square root without thinking of what would happen to it in the sines and cosines. Same goes for the multiplying by 2/2 that resulted.
Azzi, strange, I just copied and pasted it into the command window, now I'm not getting complex numbers either. It must be something in my function then.
There are sind() and cosd() versions of the functions that work directly in degrees you know.
I have updated the question with more detail...
TI1 shows up as 938.1222, which is pretty close to I01 (which it is supposed to replace) What do you mean by your question before?
Thanks, Image Analyst, I was wondering if there is something like that.
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, ...)
Thanks Alfonso and Image Analyst! I switched it to sind(180) and left alpha1 in degrees, too. Now it works. Yea, I had the plot order wrong, too.
The fit doesn't quite fit yet, but I think that's because it assumes that the resistance of the load is constant. In reality, it changes with the current (because of the changing temperature), so I will have to find some parameters for a variable resistance that depends on the current's RMS.

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 14 Nov 2013

Commented:

on 15 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!