Function runs in one script but not another ?
2 views (last 30 days)
Show older comments
working on a function about concentration, works fine in its own script conc.m but when i cpoy and paste to another script where i need it it doesn't plot a graph.
heres the function:
function[] = conc()
v = 0.00001 ;
D = 0.0000001 ;
t = 86400 ;
X = 0 : 0.01 : 2 ;
C = (1/(sqrt(4*pi*D*t)))*exp((-(X-v*t).^(2))/(4*D)) ;
plot (X, C, 'r-')
title ('Concentration of substance with respect to distance from source')
xlabel ('distance from source, m')
ylabel ('concentration, mol/l')
end
any help much appreciated
0 Comments
Answers (1)
Star Strider
on 29 Apr 2021
Vectorise its calculation, then call it —
conc
function[] = conc()
v = 0.00001 ;
D = 0.0000001 ;
t = 86400 ;
X = 0 : 0.01 : 2 ;
C = (1/(sqrt(4*pi*D*t))).*exp((-(X-v.*t).^(2))/(4*D)) ;
plot (X, C, 'r-')
title ('Concentration of substance with respect to distance from source')
xlabel ('distance from source, m')
ylabel ('concentration, mol/l')
end
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!