Problem with vpa integral
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Aviral Srivastava
le 15 Mar 2024
Commenté : Walter Roberson
le 15 Mar 2024
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);
0 commentaires
Réponse acceptée
Steven Lord
le 15 Mar 2024
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))
doubleArray = zeros(1, 5)
doubleArray(2) = sqrt2
Sometimes MATLAB cannot perform that conversion.
syms x
symArray = zeros(1, 5, 'sym')
symArray(2) = sqrt2
symArray(4) = x^2
doubleArray(4) = x^2
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 commentaires
Torsten
le 15 Mar 2024
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
le 15 Mar 2024
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!