Help with a simple function

3 次查看(过去 30 天)
Hello everybody: I am trying to write a simple function that involves an equation which is:
n2 = C1 + C2(λ^2)/((λ^2)-C3) + C4(λ^2)/((λ^2)-C5)
C1 = 1.28604141; C2 = 1.07044083; C3 = 1.00585997e-2; C4 = 1.10202242; C5 = 100
the variable should be lambda (λ) as with different values of lambda there would be different values of n. I would therefore like to assign everytime a different value for lambda and hence get the different n values associated to that lambda.
So, my question is quite simple. Could anyone give me a hint on how to start the function as the one I have created seems to have more errors than lines?
function n=nSiO2(lambda0)
lambda0=500;
C1=1.28604141;
C2=1.07044083;
C3=1.00585997e-2;
C4=1.10202242;
C5=100;
n= sqrt(C1 + C2*(lambda0^2)/((lambda0^2)-C3) + C4(lambda0^2)/((lambda0^2)-C5));
end

采纳的回答

the cyclist
the cyclist 2012-1-25
You forgot the "*" after C4, so you were trying to access a variable, instead of multipling. Does this work better?
n= sqrt(C1 + C2*(lambda0^2)/((lambda0^2)-C3) + C4*(lambda0^2)/((lambda0^2)-C5));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by