what is wrong with my code?

1 回表示 (過去 30 日間)
JJ
JJ 2021 年 4 月 28 日
編集済み: Jan 2021 年 4 月 28 日
t=86400;
v=10.^-5;
D=10.^-7;
x=0:0.01:2;
%Calcuate the concentration in ( mol/l)
conc=(1./sqrt(4*pi*D*t)*exp.(-1*((x-v*t).^2./4*D)));

採用された回答

Jan
Jan 2021 年 4 月 28 日
編集済み: Jan 2021 年 4 月 28 日
conc=(1./sqrt(4*pi*D*t)*exp.(-1*((x-v*t).^2./4*D)));
% ^
This is interpreted as "exp" beeing a struct and "(-1*((x-v*t).^2./4*D)))" is the dynamic fieldname.
Such typos are more obvious if you use spaces:
conc = 1 ./ sqrt(4 * pi * D * t) * exp(-D * (x - v * t) .^ 2 ./ 4);
The spaces avoid another ambiguity also:
a.^2./x
% Does this mean:
a .^ 2.0 / x
% or:
a .^ 2 ./ x
Although the Matlab's interpreters have strict and unique rules for these cases, a human reader can be confused.

その他の回答 (1 件)

DGM
DGM 2021 年 4 月 28 日
編集済み: DGM 2021 年 4 月 28 日
Don't need a dot in exp()
conc=(1./sqrt(4*pi*D*t)*exp(-1*((x-v*t).^2./4*D)));
This is no comment on the correctness of any math, though.

カテゴリ

Help Center および File ExchangeMATLAB Parallel Server についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by