Using a function with multiple variable
古いコメントを表示
Hello,
I am trying to create a function (from an equation) with four variables: lambda,n_crystal,n_sample and bounce_angle. A colleage of mine has been able to create code in python which defines the function and appends it and I am trying to translate it into matlab and failing.
The python code reads as follows:
def dp(lam,n_crys,n_sample,phi):
bottom=2*np.pi*n_crys*np.sqrt((np.sin(phi*np.pi/180))**2-(n_sample/n_crys)**2)
return lam/bottom
def microns_from_wavenumbers(wavenumber):
return 10000.0/wavenumber
The code above is the equation I want to define, with the only difference being my colleage replacing variable name 'bounce_angle' with 'phi'.
Ge_IOR_n_interp=interp1d(Ge_IOR_X,Ge_IOR_n,kind='linear')
wavenumbers=np.arange(1000.0,3000.1,1)
dp_Ge=[]
for wavenumber in wavenumbers:
lam=microns_from_wavenumbers(wavenumber)
beta_Ge=(180.0/np.pi)*(1/Ge_IOR_n_interp(lam))*(np.arcsin(np.pi*incidence_Ge/180.0))
bounce_angle_Ge=(90.0-incidence_Ge+beta_Ge)
dp_Ge.append(dp(lam,Ge_IOR_n_interp(lam), water_IOR_n_interp(lam), bounce_angle_Ge))
And this code shows how I want to append the function (ignore the variables). This essentially takes the interpolated files: Ge_IOR_n_interp and water_IOR_n_interp and changes the length of them to match the length of wavenumbers, then inputs them and the other calculated variables into the function to give dp_Ge a matrix of values.
This is what I have come up with in matlab:
dp = @(lam,n_crystal,n_sample,bounce_angle) lam/(2*pi*n_crytsal*sqrt((sind(bounce_angle)^2) - (n_sample/n_crystal)^2));
dp_Ge = [];
for i = 1:length(wavenumber);
lamda = 10000./wavenumber;
theta_atr_Ge = 90 - a_Ge;
dp_Ge = append(f(lamda,Ge_interp,water_interp,theta_atr_Ge));
end
This doesn't work, but after reading about anonymous functions I'm still lost as to where I've gone wrong.
Any help is thoroughly appreciated!
採用された回答
その他の回答 (1 件)
Walter Roberson
2019 年 1 月 7 日
0 投票
dp_Ge(i,:) = f(lamda, other parameters )
4 件のコメント
mabinj
2019 年 1 月 7 日
Walter Roberson
2019 年 1 月 7 日
no colon at the end of for. MATLAB does not use colon to separate statement parts like python does.
mabinj
2019 年 1 月 7 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!