converting from sym to double

17 次查看(过去 30 天)
Jama Ali
Jama Ali 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 个)

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.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by