Problem with vpa integral

14 次查看(过去 30 天)
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);

采纳的回答

Steven Lord
Steven Lord 2024-3-15
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 个评论
Torsten
Torsten 2024-3-15
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.
Walter Roberson
Walter Roberson 2024-3-15
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.

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by