translating commands from python
3 次查看(过去 30 天)
显示 更早的评论
So I'm trying to translate the following code from Python:
def chabrier03individual(m):
k = 0.158 * exp(-(-log(0.08))**2/(2 * 0.69**2))
return numpy.where(m <= 1,\
0.158*(1./m) * exp(-(log(m)-log(0.08))**2/(2 * 0.69**2)),\
k*m**-2.3)
And end up stuck with an incorrect if statement:
% Initial Conditions
clearvars
close all
Ms=1.989E30;
m = logspace(-2, 2, 400);
% m = 1E2:100:1E4
% (m<0.08, m**-0.3, numpy.where(m < 0.5, 0.08**-0.3 * (m/0.08)**-1.3, 0.08**-0.3 * (0.5/0.08)**-1.3 * (m/0.5)**-2.3))
%% def chabrier03individual(m):
k = 0.158*exp(-(-log(0.08))^2/(2*0.69^2))
if m<=1
u = 0.158*(1./m)*exp(-(log(m)-log(0.08))^2/(2 * 0.69^2));
else
v = k*m;
end
Where am I going wrong?
2 个评论
Geoff Hayes
2020-1-31
HC98 - m appears to be an array with 400 elements, so what are you expecting to happen with
if m<=1
Is this logic that you want to apply to each element of m? Also, why is u used if m<=1 but v used for the else?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!