converting from sym to double

9 vues (au cours des 30 derniers jours)
Jama Ali
Jama Ali le 4 Oct 2020
Hi, how do i overcome this problem:
"The following error occurred converting from sym to double:
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function
first to substitute values for variables."
I integrated cosine function and the matrix are in the form of symbols.
  2 commentaires
Ameer Hamza
Ameer Hamza le 4 Oct 2020
Can you show the code?
Jama Ali
Jama Ali le 4 Oct 2020

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 4 Oct 2020
There are a few different reasons why that can happen:
  • Your formula has at least one unbound symbolic variable. This is likely your problem.
  • your formula involves a symbolic integral that does not appear to converge
  • your formula involves numbers too large for the symbolic toolbox to represent. I do not recall the exact limit at the moment but it is beyond 10^300000
  • your formula involves the root() of an equation that involves software floating point numbers, but to the current number of digits active, it is not possible to find the root because the equation is too nonlinear
  1 commentaire
Walter Roberson
Walter Roberson le 4 Oct 2020
For the first case you need to subs() particular numeric values for each of the variables.

Connectez-vous pour commenter.


Bjorn Gustavsson
Bjorn Gustavsson le 4 Oct 2020
Most of the time I want to convert a symbolic expression to something else I use matlabFunction:
syms s x real
f = int(cos(s^2),0,x);
% returns:
% f =
%
% (2^(1/2)*pi^(1/2)*fresnelc((2^(1/2)*x)/pi^(1/2)))/2
%
% Convert that to a matlab-function-handle for use on arbitrary x:
F = matlabFunction(f);
% returns:
% F =
%
% function_handle with value:
%
% @(x)sqrt(2.0).*sqrt(pi).*fresnelc(sqrt(2.0).*x.*1.0./sqrt(pi)).*(1.0./2.0)
%
F([1 12])
% Returns:
% ans =
%
% 0.9045 0.6061
HTH
  3 commentaires
Walter Roberson
Walter Roberson le 4 Oct 2020
fplot the results of integration
Bjorn Gustavsson
Bjorn Gustavsson le 4 Oct 2020
Change f to:
f = cos(w*t);
Change the integration to something like this:
I = int(f,w,w0,w1);
Then convert I to F.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by