converting from sym to double

9 ビュー (過去 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 Center および File ExchangeConversion 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