Matlab giving incorrect graph for exponential function
이전 댓글 표시
Hey, So i'm trying to plot a graph in matlab
n=1.3390
S=2.9368e-05
T=0.0259
fplot(((T^2*n^2.*exp(-(x)./(T*n))).*(((((S^2).*exp((2.*x)/(T*n)))/((T^2)*(n^2)))+1).^(3/2)))/S);
And substituting the values looks like this(without matrix scalar points):
y=((((0.0259)^2*(1.3390)^2*exp(-(x)/((0.0259)*(1.3390))))*((((((2.9368e-05)^2)*exp((2*x)/((0.0259)*(1.3390))))/(((0.0259)^2)*((1.3390)^2)))+1)^(3/2)))/(2.9368e-05))
this graph should look like this (graph from geogebra)

But when I graph it in matlab i I'm not getting the correct graph; I either get an incorrect graph, or something that doesn't make any sense, like this

댓글 수: 2
KSSV
2017년 2월 14일
That doesn't mean MATLAB is wrong. You have to check your code.
Joshua Carpeggiani
2017년 2월 14일
답변 (1개)
John D'Errico
2017년 2월 14일
No. Sorry, but you have not written a function that has the properties you claim. In fact, I have a funny feeling that what you have shown us is not what you did anyway, because if you try to execute that line with fplot in it, as you show, it will generate an error message:
n=1.3390
S=2.9368e-05
T=0.0259
fplot(((T^2*n^2.*exp(-(x)./(T*n))).*(((((S^2).*exp((2.*x)/(T*n)))/((T^2)*(n^2)))+1).^(3/2)))/S);
Undefined function or variable 'x'.
That is not a valid call to fplot.
It does generate a plot if I turn that line into a function.
Next, if you read the help for fplot, you would see that it plots the function between the limits [-5,5]. So all the way from -5 to 5. Your function EXPLODES over those limits.
So if instead, I restrict fplot to look at a limited region, then we get a plot, with at least finite values in it.
fplot(@(x) ((T^2*n^2.*exp(-(x)./(T*n))).*(((((S^2).*exp((2.*x)/(T*n)))/((T^2)*(n^2)))+1).^(3/2)))/S,[0.05,0.35]);

It still is not the simple parabola that you seem to expect. So you are still doing something wrong. I have no idea what you plotted in that other tool, but this is not the function that you seem to expect. But then, since you show only the code and not the true function you think you wrote code for, how can I know?
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!