필터 지우기
필터 지우기

Problem with vpa integral

조회 수: 5 (최근 30일)
Aviral Srivastava
Aviral Srivastava 2024년 3월 15일
댓글: Walter Roberson 2024년 3월 15일
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개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by