开发者

??? Error using ==> plot - conversion to double from sym is not possible

I'm having some problems with my code. Here it is:

lambdaz = 1.2;
n = 24;
mu = 0.00055e9;

lambda = sym('lambda','clear');
W = (((2.*mu)./n.^2)).*((lambda.^n)+(lambdaz.^n)+((lambda.^-n).*(lambdaz.^-n))开发者_开发问答-3);
dW_dlambda = diff(W, lambda);

W2=(((2.*mu)./n.^2).*(lambda.^n))+(((2.*mu)./n.^2).*(lambdaz.^n))+(((2.*mu)./n.^2).*((lambda.^-n).*(lambdaz.^-n)))-(3.*((2.*mu)./n.^2))
dW2_dlambda=diff(W2,lambda)

x=((((lambda.^2).*(lambdaz))-1).^-1).*(dW_dlambda);

x2=((((lambda.^2).*(lambdaz))-1).^-1).*(dW2_dlambda)

P2 = int(x2,lambda)

P=int(x,lambda);
P=(0:1000:26700)

plot(lambda,P)

When I try to plot lambda against P I get the "conversion to double from sym is not possible" error message. I'm not particularly fantastic at Matlab so any help would be gratefully received!


The plot function only works for numeric inputs. Both lambda and P are symbolic expressions (at least before overwrote P by setting it equal to a vector after the integration) that cannot be directly converted to to floating point. You get the same error if try to something like double(sym('exp(x)')). You have two options. The first is the ezplot function in the Symbolic Toolbox:

...
P = int(x,lambda);
ezplot(P,[-5 5]); % Plot's P from lambda = -5 to lambda = 5

Or you can use the subs function:

...
P = int(x,lambda);
lambda = -5:0.01:5;
plot(lambda,real(subs(P,'lambda',lambda)))
axis([lambda(1) lambda(end) -1e15 1e15])

I used real to suppress a warning for negative values of lambda.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜