keep from evaluating a symbolic expression

9 ビュー (過去 30 日間)
Chad
Chad 2022 年 7 月 3 日
回答済み: Walter Roberson 2022 年 7 月 5 日
Utter noob question but Im trying to build up a function and see it in with nice formatting in live script how do I keep it from evaluating?
Say below I want to make sure that I have typed it in correctly not auto evaluate it . Also is there anyway to use e as asymbol and not have it automatically evaluate it into its fractional form? Sorry for how basic this is Im sadly only on hour number 3 of this langauge .
4*pi^2 * (2*pi*100)^2 *1/5
  2 件のコメント
Abhijeet
Abhijeet 2022 年 7 月 4 日
Hi, Chad
In the sentence "Also is there anyway to use e as asymbol", here 'e' is an exponential constant?
Walter Roberson
Walter Roberson 2022 年 7 月 4 日
Pi = sym(pi);
E = exp(sym(1));
4*Pi^2 * (2*E*100)^2 * 1/5
ans = 

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

回答 (2 件)

Abhijeet
Abhijeet 2022 年 7 月 4 日
Hi, Chad
I understand you want to visualize the expression without it getting evaluated.
This can be achieved using symbolic variables, but still, constants will be evaluated to a simplified expression.
Create ‘pi’ as a symbolic variable as demonstrated below:
Use 'e' as a symbolic variable to represent ‘e’ as an exponent constant without it getting evaluated.
Here is a demonstration to create symbolic variables:
For more insights on symbolic variables, kindly visit the below mentioned hyperlinks:
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 5 日
There was a long period during which
syms pi
would make pi into a symbolic variable that referred to the transcendental constant π. However, that is no longer the case; now syms pi makes pi into an ordinary variable that does not refer to the constant (the situation is a little stranger than that internally.)
These days, to get LiveScript to display π for values that refer to the transcendental constant, use
pi = sym(pi);
or do like I did, of using Pi for that purpose instead, so that the numeric pi remains accessible.
See the difference:
syms pi
vpa(pi)
ans = 
π
clear pi
pi = sym(pi)
pi = 
π
vpa(pi)
ans = 
3.1415926535897932384626433832795
Chad
Chad 2022 年 7 月 5 日
Awesome , thanks for yalls help

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


Walter Roberson
Walter Roberson 2022 年 7 月 5 日
You can use displayFormula on the character (or string()) version of the formula, and later convert that to symbolic
as_char = '4*pi^2 * (2*pi*100)^2 *1/5'
as_char = '4*pi^2 * (2*pi*100)^2 *1/5'
displayFormula(as_char)
as_sym = str2sym(as_char)
as_sym = 

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by