Info

This question is closed. Reopen it to edit or answer.

I am complete new , and do not know how to modify this~

1 view (last 30 days)
syms x
T=1;
lamda=0.5;
gamma=1;
t=0.1;
theta=0.1;
U=lamda/(0.5*theta^2+lamda);
V0(x)=-U.*exp(-gamma.*x)+(1-U).*exp(-(0.5.*theta.^2+lamda).*(T-t)).*exp(-gamma.*x);
R=-diff(V0)./diff(V0,2)
Error:
The following error occurred converting from sym to double:
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.

Answers (1)

Walter Roberson
Walter Roberson on 14 Nov 2015
Edited: Walter Roberson on 14 Nov 2015
You have
V0(x)=-U.*exp(-gamma.*x)+(1-U).*exp(-(0.5.*theta.^2+lamda).*(T-t)).*exp(-gamma.*x);
which attempts to index something at the symbolic variable x. Your MATLAB is attempting to convert that symbolic x into a numeric value to use as an index in to V0.
You need to add
syms V0(x)
before you have that statement so that MATLAB knows you are defining a symbolic function.
If MATLAB complains about
syms V0(x)
being a syntax error then you have a version of MATLAB that is too old to support that. If that happens then instead use
V0 = -U.*exp(-gamma.*x)+(1-U).*exp(-(0.5.*theta.^2+lamda).*(T-t)).*exp(-gamma.*x);
R = -diff(V0,x) ./ diff(V0,x,2);
  1 Comment
Shican Liu
Shican Liu on 15 Nov 2015
Yeah, that is right, my matlab is an old version, but it's already done, 3Q very much~~

Community Treasure Hunt

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

Start Hunting!