Problem with integration using sym in case of "sym is not convertible to double"

14 visualizzazioni (ultimi 30 giorni)
The term in integration is having size 1*1, so it is not an array or matrix, still sym is showing problem with double. Can someone help me in this.
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.
temp=int((1/(det(eye(Nr*Nt*(2^mrf))+((C_z*B)./(4*No*(sin(theta))^2))))) ...
*exp(-(1/(4*No*(sin(theta))^2))*(P_bar')*B*(inv(eye(Nr*Nt*(2^mrf))+((C_z*B)./(4*No*(sin(theta))^2))))*(P_bar)),'theta',0,pi/2)/pi;
Caused by:Error using symengine, Unable to convert expression containing remaining symbolic function calls into double array. Argument must be expression that evaluates to number.

Risposta accettata

Cris LaPierre
Cris LaPierre il 25 Mar 2023

Più risposte (1)

Walter Roberson
Walter Roberson il 25 Mar 2023
One or more of the things that look like variables in your expression are symbolic functions. You should invoke each of the symbolic functions on appropriate variables. For example if B is a symbolic function in theta then code B(theta) instead of B.
This will take care of that exact error message. It might instead change it to complain that variables of type sym cannot be converted to double.
Now, normally in MATLAB an assignment like that would overwrite the output variable completely, and you would not get an error there at that particular line, but might get it on a later step such as if you had
y(K) = temp;
The situation where you could get that error there is if you are doing this calculation inside a MATLAB Function Block in Simulink and had used the appropriate coder.external calls to be able to call the symbolic functions, and you had previously done
temp = 0;
or otherwise assigned a double to temp before that line. In such a case, Simulink would try to convert the result of int() to double automatically. For debugging purposes, assign to a different variable and test symvar() of the other variable to be sure that the int worked before assigning the result to temp.
Note that you can only use symbolic calculations in MATLAB Function Block if acceleration is off.
You might at first think "oh yes, the same kind of problem could occur if you were using MATLAB Coder with MATLAB Code" (instead of inside Simulink), but MATLAB Coder cannot process anything about the Symbolic Toolbox, so this particular issue with automatic conversion to double can only occur in Simulink.
Ummm, except possibly if you had used the new "arguments" facility to declare the types of output arguments... I don't know how that works.

Community Treasure Hunt

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

Start Hunting!

Translated by