Calculation giving me complex numbers exen though it shlouldn't

1 view (last 30 days)
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
Alfonso Nieto-Castanon
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
Marc Jakobi on 15 Nov 2013
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 Elementary Math 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!