【问题标题】:How to solve symbolic equation in matlab如何在matlab中求解符号方程
【发布时间】:2012-12-16 17:16:53
【问题描述】:

我在 Matlab 中有一个根据 X 参数的方程。我想为 F(x) 的随机数量找到 X 的数量。 我尝试了下面的代码。但它给了我两个不同的结果,而我的方程应该只有一个结果。

即使我尝试了roots(f) 而不是solve(f),但它给了我一个错误:

???输入参数的未定义函数或方法“isfinite” 输入“符号”。

任何人都可以帮助我吗? 我该怎么办 ? 即使我对解决这个问题有错误的想法,请告诉我。 谢谢你

函数 betaDistribution_2(a,b)

    syms  x ;
    y=inline((x^(a-1))*((1-x)^(b-1)));
    beta=quad(y,0,1);
    g=(1/beta)*(x^(a-1))*((1-x)^(b-1));
    % I have this equation and I want to find the amount of x for the random 
    %amounts of p 
    p=int(g,x,0,x); 

    for i=0:50
       fxi=rand(1);
       f=p-fxi;
       xi=solve(f);
       result=eval(xi);
       disp(result)
    end

    end

【问题讨论】:

  • 您究竟在哪里得到错误?此外,您可能希望在使用 dbstop if error 隔离/解决问题后运行代码。
  • 在我使用 {roots(f)} 而不是 {solve(f)} 并使用 {betaDistribution_2(1,2)} 在工作空间中运行程序后,我得到了这个错误??? 'sym' 类型的输入参数的未定义函数或方法 'isfinite'。

标签: matlab equation-solving


【解决方案1】:

尝试过滤您的解决方案。

a=1;
b=2;
% a threshold for imagery part
SMALL=1e-9;

syms x real;
y=inline((x^(a-1))*((1-x)^(b-1)));
beta=quad(y,0,1);
g=(1/beta)*(x^(a-1))*((1-x)^(b-1));
p=int(g,x,0,x);

% return true for physically meaningfull results
filter = @(xc) abs(imag(xc))<SMALL && real(xc)>0 && subs(g, x, xc) > 0 && subs(p, x, xc)>0;

for m=0:50
  fxi=rand(1);
  f=p-fxi;
  xi=solve(f, x);
  result=eval(xi);

  idx = arrayfun (filter, result);
  result = result(idx);
  % make sure it is OK
  assert(length(result)==1);
  disp(result)
end

【讨论】:

  • 没有。这两个结果都是真实的。
  • 您的系统可能有多个解决方案,但其中只有一个具有物理意义。 ab 的范围是多少?
  • 当我尝试 a=1 , b=2 时,我得到了 2 个结果。当我尝试 a=3 , b=4 时,我得到了 4 个结果!!!!!!!!!
  • a 和 b 的范围可能不同,这取决于用户的意见。
  • 我看到你重新定义了i。它弄乱了图像编号。最好更改它并执行clean
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多