Vu(k,T) = ((gama_q.*(g2).*(T^2)))./(2*k);
Vii_u(k,T) = diff(Vu ,k );
rho_u(k,T) = (-Vii_u).*(Vu^2)*l1;
%Fi_u = matlabFunction(rho_u.*l1);
Fii( 1 ) = vpaintegral(rho_u, k_min_q ,4*k_min_q);
P.S. I am using vpaintegral becasue int does not yield a functional expression and fails to calculate integral. I tried numerical approach but the error is above the bounds. Once I get Fii as a function of T then I need to differenciate Fii w.r.t T.
k and T are sym variables;
g2 is another sym expression of the following form
g2(k) = N./log(1 + ((k.^2)./lambda^2));
I want Fii(1) to be an integrak done w.r.t k so that the resultant expression is a function of only T.
I am getting the follwing error:
The following error occurred converting from symfun to double:
Unable to convert expression into double array.
Error in m_t_u_B2_transition (line 61)
Fii( 1 ) = vpaintegral(rho_u, k_min_q ,4*k_min_q);

 Accepted Answer

This type of error indicates you're assiging a symbolic expression into an element of a double array. When you do this, MATLAB will attempt to convert the symbolic expression into double so it "fits" in the double array. Sometimes this works.
sqrt2 = sqrt(sym(2))
sqrt2 = 
doubleArray = zeros(1, 5)
doubleArray = 1×5
0 0 0 0 0
doubleArray(2) = sqrt2
doubleArray = 1×5
0 1.4142 0 0 0
Sometimes MATLAB cannot perform that conversion.
syms x
symArray = zeros(1, 5, 'sym')
symArray = 
symArray(2) = sqrt2
symArray = 
symArray(4) = x^2
symArray = 
doubleArray(4) = x^2
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.

Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Two potential ways to resolve this error could be to substitute numeric values into the symbolic expression, so instead of a value like "x^2" it has a numeric value (if I substituted x = 3 into the symbolic expression x^2, MATLAB would store the value 9 in doubleArray(4)) or to define the array as symbolic at the start rather than double (like I did with symArray above.)

5 Comments

Hello, Thanks for the prompt reply.
I have not used any such conversion anywhere in my code. That is why I am not able to figure out why is this occuring. I will tell you some intricacies about this code snippet:
gama_q is a numerical constant
g2 is a symbolic function of k only
l1 is another symbolic function of T and k of the form:
log(1 - exp(-k^2 + 1/T))
I have not used any such conversion anywhere in my code.
Not explicitly, no. But when you try to assign a value of one data type to a subset of an array that's a different data type, MATLAB must[*] implicitly convert the data being assigned into the type of the array you're trying to assign into.
d = [0 0 0] % double
d = 1×3
0 0 0
s = single(pi) % single
s = single 3.1416
d(2) = s % converts single(pi) into double then stores that result into d(2)
d = 1×3
0 3.1416 0
class(d(2)) % double not single
ans = 'double'
[*] One example where this isn't the case is for heterogeneous arrays. But that's an advanced use case.
So how do I fix this in the perview of this code?
We might be able to help if you supply executable code that reproduces the error message you get. The code from above is incomplete because sym declarations and/or parameters are missing.
Fii( 1 ) = vpaintegral(rho_u, k_min_q ,4*k_min_q);
You must have previously assigned Fii as a numeric array. You need to insert
Fii = sym(Fii);
before the above statement to fix this problem.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!