From: Bastian Baudisch on
Hey Guys,

I'm trying to conduct a fit of my measurements to the formula for the reflection coefficients:

f=@(n1,t) abs(((sqrt(n1.^2 - (sin(t*pi/180)).^2) - cos(t*pi/180)).^2)/(1 - n1.^2));
%Fit-Funktion für r_senkrecht

g=@(n2,t) abs((n2.^2*cos(t*pi/180)-sqrt(n2.^2-(sin(t*pi/180)).^2))/...
(n2.^2*cos(t*pi/180)+sqrt(n2.^2-(sin(t*pi/180)).^2)));
%Fit-Funktion für r_parallel

unsing the following syntax:

ns1=1.3; ns2=1.5;
par_senk=nlinfit(x,y_senk,f,ns1);
par_parr=nlinfit(x,y_parr,g,ns2);

With funcion f evetrything's fine, bit with g MATLAB seems to experience problems due to the nonconstant denominator (even though it sholdn't go to zero).

The Error Messanges read:

??? Error using ==> nlinfit at 127
MODELFUN should return a vector of fitted values the same length as Y.

Error in ==> mat_fresnel at 13
par_parr=nlinfit(x,y_parr,g,ns2);

Error in ==> run at 57
evalin('caller', [s ';']);

I so far found out that that while function f behaves perfectly normal, yielding a vector, g's output seems to be a martix!
E.g. g (ns2, x) yields a matrix consisting of a vector in the first column followed by 10 more columns with all elements being 0. I guess this is what screws up nlinfit.

Now I want to restrict my parameters n2 to the positive regime - can you do that using "nilnfit"? Or else, does anyone know how o get to the bottom of the whole problem?

Thanks in andvance for your input.

Cheers, Bastian
From: Tom Lane on
> g=@(n2,t) abs((n2.^2*cos(t*pi/180)-sqrt(n2.^2-(sin(t*pi/180)).^2))/...
> (n2.^2*cos(t*pi/180)+sqrt(n2.^2-(sin(t*pi/180)).^2)));

Bastian, you have matrix division here with "/". Try using "./" instead for
element-by-element division.

-- Tom


From: Bastian Baudisch on
Thanks a lot!
I checked for all the ".^2"s ant the other divisions, but somehow overlooked the obvious.. must have been staring at it for too long^^