1

I'm going to plot a function in MuPAD tool in Matlab, it seems it's not correct.

my function in (MuPAD) is:

P = exp(-10)*10^n/n!
plot(P, n=0:24);

and in a regular m-file is:

n=0:24;
P = exp(-10).*(10.^n)/factorial(n);
plot(n,P);

Its result is diagonal line which is not true. However, the same function in regular m file script is plotted very well. Any idea?

Super Hornet
  • 2,839
  • 5
  • 27
  • 55
  • Sure you are using the exact code? I'd rather expected to define `n` before actually calculating `P` (the way you do it should get you an undefined error), or by defining P as a anonymous function (`P = @(n) ....`) Maybe you run the script in Matlab before so that n was defined before actually calling/running it again, thus it worked in matlanb... – tim May 14 '16 at 10:58
  • I assume you did not even try your code before in MATLAB... `n!` is not valid in MATLAB to calculate the factorial: https://de.mathworks.com/help/matlab/ref/factorial.html – tim May 14 '16 at 11:01
  • @tim, n! is valid in MuPAD not in m-files – Super Hornet May 15 '16 at 08:14
  • Alright I was assuming the identical code was used in the m-script. Then please also post the m-file which is plotted alright in MATLAB :-) – tim May 15 '16 at 08:34
  • @tim, m-file version code is included – Super Hornet May 15 '16 at 11:42

0 Answers0