converting from sym to double

조회 수: 12 (최근 30일)
Jama Ali
Jama Ali 2020년 10월 4일
댓글: Bjorn Gustavsson 2020년 10월 4일
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
Ameer Hamza
Ameer Hamza 2020년 10월 4일
Can you show the code?
Jama Ali
Jama Ali 2020년 10월 4일

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2020년 10월 4일
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
Walter Roberson
Walter Roberson 2020년 10월 4일
For the first case you need to subs() particular numeric values for each of the variables.

댓글을 달려면 로그인하십시오.


Bjorn Gustavsson
Bjorn Gustavsson 2020년 10월 4일
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
Walter Roberson
Walter Roberson 2020년 10월 4일
fplot the results of integration
Bjorn Gustavsson
Bjorn Gustavsson 2020년 10월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

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