Substituting an expression not giving intended result

3 ビュー (過去 30 日間)
John
John 2019 年 1 月 7 日
コメント済み: Star Strider 2019 年 1 月 7 日
I'm trying to simplify the following expression using the subs function. In the code below, I was expecting Asubs = 3*Phi. Any ideas on what might be wrong in my code?
clear all;
clc;
syms phi(c,cbar,sigma) Phi(c,cbar,sigma) A(csol,cbar,sigma)
assumeAlso(sigma,'real')
assumeAlso(sigma>0)
phi(c,cbar,sigma)= (1/sqrt(2*sym(pi)*sigma^2))*exp(-(c-cbar)^2/(2*sigma^2))
A(csol,cbar,sigma)=3*int(phi(c,cbar,sigma),c,-inf,csol)
Phi(csol,cbar,sigma) = 1/2 + 1/2*erf(sqrt(2)*(csol-cbar)/(2*sigma))
%Phi(x,sigma) = 1/2 + 1/2*erf(sqrt(2)*(x)/(2*sigma))
Asubs = subs(A,Phi)

採用された回答

Star Strider
Star Strider 2019 年 1 月 7 日
Since ‘Phi’ does not appear as such specifically in ‘A’, the substitution will fail.
Perhaps this is closer to what you want:
As = simplify(A/Phi)
prodcing:
As(csol, cbar, sigma) =
3
  2 件のコメント
John
John 2019 年 1 月 7 日
I see. The code in the question is a kind of mwe for the following problem. The normal distribution CDF and PDF appear in many of the formulas that I'm working. I wanted to shorten those formulas by using $\Phi$ and $\phi$ to represent them in the expressions. In case you know of a workaround, I'd love to hear.
Star Strider
Star Strider 2019 年 1 月 7 日
I am still at a loss to understand what you are doing.
I would not use the Symbolic Math Toolbox for such calculations. It is primarily designed for derivations and other such. Use the matlabFunction (link) function to create anonymous functions from your symbolic functions. Then use them in your calculations.

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 7 日
syms c cbar sigma Phi A csol
assumeAlso(sigma,'real')
assumeAlso(sigma>0)
phi(c,cbar,sigma)= (1/sqrt(2*sym(pi)*sigma^2))*exp(-(c-cbar)^2/(2*sigma^2))
A(csol,cbar,sigma)=3*int(phi(c,cbar,sigma),c,-inf,csol)
Phi(csol,cbar,sigma) = 1/2 + 1/2*erf(sqrt(2)*(csol-cbar)/(2*sigma))
%Phi(x,sigma) = 1/2 + 1/2*erf(sqrt(2)*(x)/(2*sigma))
Asubs = vpa(subs(A,Phi)) % cbar csol and sigma values are not known
  2 件のコメント
John
John 2019 年 1 月 7 日
This doesn't make the substitution. It only evaluates the square roots, pi, etc
madhan ravi
madhan ravi 2019 年 1 月 7 日
because cbar csol and sigma are symbolic variables

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by