ploting exponential integral function

3 次查看(过去 30 天)
BJ
BJ 2011-3-17
Hi, I'm trying to plot integral of x*exp(-1/x). These are my code,
syms x y1 y2;
y1=x*exp(-1/x);
y2=int(y1)
ezplot(y2)
I've got this error message,
??? Error using ==> inlineeval at 15 Error in inline expression ==> - Ei(-1./x)./2 - (x.^2./(2.*exp(1./x)) - x.^3./(2.*exp(1./x)))./x Undefined function or method 'Ei' for input arguments of type 'double'.
How could I plot it ? Many thanks BJ

回答(1 个)

Laura Proctor
Laura Proctor 2011-3-17
You can plot it by defining your range of x values and then plugging this into y, something like this:
x = -0.5:0.01:0.5;
y = x.*exp(-1./x);
plot(x,y,'.')
axis([ -0.5 0.5 -10 0.5])
A few comments on this code:
The first line defines a vector of x-values using the colon operator.
The second line uses element-wise multiplication and division rather than matrix multiplication and division denoted by the dot in front of the operator. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/br02znk-1.html#br02znk-6
The third line is plotting x versus y with the dot marker (third input). You can learn more about customizing your plots here: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/linespec.html
The fourth line zooms in on the plot using the AXIS command.
  4 个评论
Laura Proctor
Laura Proctor 2011-3-17
Ei is an MFUN function and these do not play well with EZPLOT because EZPLOT looks to be directly plugging in numeric values to create the plot. For MFUN functions, numeric values need to be plugged in with MFUN and cannot be plugged in directly.
Walter Roberson
Walter Roberson 2011-3-17
This is part of a more general problem that there is a bug report or technical solution for (that I'd have to locate.) If you use matlabFunction() or inline() to convert symbolic expressions to Matlab, then some calls (such as ln) do not get translated to their Matlab equivalents, and others (such as Ei) have no Matlab equivalents to be translated to.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by