Change exp from number to e

6 ビュー (過去 30 日間)
Gregorio Garza Treviño
Gregorio Garza Treviño 2022 年 9 月 19 日
回答済み: Paul 2022 年 9 月 19 日
Im doing a little work on matlab and Im trying to type some expressions that include the number e. However, when I do this, instead of putting the e, it puts a fraction that aprroximates the value. Does anyone know how to change this?
syms c1 c2 y(x) f(x)
y(x) = (exp(2)/(exp(2)+1))*exp(-x)+(1/(exp(2)+1))*exp(x)
y(x) = 
ans = y(0)
ans = 
And as you can see, this causes it to not give an exact answer, y(0) should be 1, when it instead gives a really close approximation

採用された回答

Rik
Rik 2022 年 9 月 19 日
Your own suggestion actually works (although it requires a call to simplify):
syms c1 c2 y(x) f(x) e
y(x) = (e^2/(e^2+1))*e^(-x)+(1/(e^2+1))*e^x
y(x) = 
y=simplify(y)
y(x) = 
y(0)
ans = 
1
You can also use subs to substitute e with exp(1).

その他の回答 (1 件)

Paul
Paul 2022 年 9 月 19 日
Use sym arguments to exp, otherwise it reverts to the base Matlab numerical function.
syms c1 c2 y(x) f(x)
y(x) = (exp(sym(2))/(exp(sym(2))+1))*exp(-x)+(1/(exp(sym(2))+1))*exp(x)
y(x) = 
Evaluate at some values
simplify(y([0 1 2]))
ans = 
vpa(ans) % etc.
ans = 

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by