Tutorial Symbolic
Tutorial Symbolic
sym(ans)
ans =
9/20
whos
Name Size Bytes Class Attributes
whos
Name Size Bytes Class Attributes
ans =
0.3636
ans =
format compact
clc
sym(0.5 + 1/2)
ans =
1
y=[1 2]
y =
1 2
sym(4.25+11/2)
ans =
39/4
double(ans)
ans =
9.7500
sym(2042/32+22455/12)
ans =
30961/16
double(ans)
ans =
1.9351e+03
format
ans
ans =
1.9351e+03
clc
vpa(11/120)
ans =
0.091666666666666666666666666666667
digit(10)
{#Unrecognized function or variable 'digit'.
}#
digits(10)
vpa(11/120)
ans =
0.09166666667
clc
0.9999999999999 + 1
ans =
2.0000
vpa(0.999999999999+1)
ans =
2.0
4.14 + sym(11/20)
ans =
469/100
area =
12.5664
d = 2; % another comment
%amfkeg
%kdmvfv...
%kndfnffn
%ded
eff
{#Unrecognized function or variable 'eff'.
}#
clc
format shorteng
8/3
ans =
2.6667e+000
format short e
8/3
ans =
2.6667e+00
2949/12
ans =
2.4575e+02
format short g
8/3
ans =
2.6667
1/3
ans =
0.33333
10/3
ans =
3.3333
0.1 + 0.200
ans =
0.3
format compact
ans
ans =
0.3
clc
x = syms('x')
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('syms',
'C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\syms.m', 137)"
style="font-weight:bold">syms</a> (<a href="matlab: opentoline('C:\Program
Files\Polyspace\R2020a\toolbox\symbolic\symbolic\syms.m',137,0)">line 137</a>)
Using input and output arguments simultaneously is not supported.}#
x = sym('x')
x =
x
% metavlhtes sto symbolic
% allos tropos
y = syms('z')
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('syms',
'C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\syms.m', 137)"
style="font-weight:bold">syms</a> (<a href="matlab: opentoline('C:\Program
Files\Polyspace\R2020a\toolbox\symbolic\symbolic\syms.m',137,0)">line 137</a>)
Using input and output arguments simultaneously is not supported.}#
y = sym('z')
y =
z
syms y
syms z
% _ = sym('_') dhmiourgei metavlhth me timh to onoma ths ws sumvolo
clc
syms a1 a2 a3 a4
a1
a1 =
a1
a1 = sym(1/2)
a1 =
1/2
% to matlab apo8ikeuse to sumvolo 1/2 sthn a1, oxi ton ari8mo 0.5
x*2
ans =
2*x
a1*2
ans =
1
0.499999999*2
ans =
1
0.49*2
ans =
0.98
x = x^2
x =
x^2
clc
r = sym(1/100)
r =
1/100
3*r
ans =
3/100
r^3
ans =
1/1000000
syms chris
clc
r = 0.75;
area = pi*r^2
area =
1.7671
area = sym(pi*r^2)
area =
(9*pi)/16
x
x =
x^2
x = sym(sqrt(x))
x =
(x^2)^(1/2)
syms x
y = sym('x')
y =
x
y==x
ans =
x == x
area
area =
(9*pi)/16
% metatrepw ton ari8mo se dekadiko
area = double(area)
area =
1.7671
area = sym(pi*r^2)
area =
(9*pi)/16
% entolh pretty
area = pretty(area)
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym/pretty')"
style="font-weight:bold">sym/pretty</a>
Too many output arguments.}#
pretty(area)
9 pi
----
16
clc
area
area =
(9*pi)/16
clc
a2^2
ans =
a2^2
pretty(ans)
2
a2
a1
a1 =
1/2
a1 = sym(sqrt(2))
a1 =
2^(1/2)
pretty(a1)
sqrt(2)
pretty(sym(abs(-1)))
1
pretty(sym(ceil(-0.1)))
0
pretty(sym(ceil(1.1)))
2
x
x =
x
% algevra gumnasiou!
x^3/x
ans =
x^2
pretty(ans)
2
x
(x^2-4)/(x-2)
ans =
(x^2 - 4)/(x - 2)
simplify((x^2-4)/(x-2))
ans =
x + 2
simplify((sin(x))^2+(cos(x))^2)
ans =
1
factorial(5)
ans =
120
rt = sym(ntroot(2,3))
{#Unrecognized function or variable 'ntroot'.}#
rt = sym(nthroot(2,3))
rt =
5674179970822795/4503599627370496
pretty(rt)
5674179970822795
----------------
4503599627370496
x
x =
x
simplify((sqrt(x))^2)
ans =
x
simplify((sqrt(x^2)))
ans =
(x^2)^(1/2)
clc
whos
Name Size Bytes Class Attributes
a1 1x1 8 sym
a2 1x1 8 sym
a3 1x1 8 sym
a4 1x1 8 sym
ans 1x1 8 sym
area 1x1 8 sym
chris 1x1 8 sym
d 1x1 8 double
r 1x1 8 double
rt 1x1 8 sym
x 1x1 8 sym
y 1x1 8 sym
z 1x1 8 sym
clc
sin(10)
ans =
-0.54402
sin(pi)
ans =
1.2246e-16
sym(sin(pi))
ans =
4967757600021511/40564819207303340847894502572032
pi
ans =
3.1416
p = sym(pi)
p =
pi
sym(sin(p))
ans =
0
format
p
p =
pi
format compact
p
p =
pi
cos(p/2)
ans =
0
syms pi
cos(p/2)
ans =
0
cos(pi/2)
ans =
cos(pi/2)
p
p =
pi
pi
pi =
pi
clc
% gia euresh trigwnometrikwn timwn..
p = sym(pi)
p =
pi
cos(p/4)
ans =
cos(pi/4)
sym(cos(p/4))
ans =
cos(pi/4)
p = sym('pi')
p =
pi
sym(sin(p))
ans =
sin(pi)
p = sym(pi)
p =
pi
sym(cos(pi))
ans =
cos(pi)
cos(p)
ans =
cos(pi)
sin(p)
ans =
sin(pi)
clc
clear
sin(30)
ans =
-0.9880
sind(30 * pi/180) % hmitono se moires
ans =
0.0091
sind(pi/6)
ans =
0.0091
sym(sin(60 * pi/180))
ans =
3^(1/2)/2
pretty(ans)
sqrt(3)
-------
2
% poio to sin(pi)?
pretty(sym(sin(pi)))
4967757600021511
--------------------------------
40564819207303340847894502572032
pretty(sym(sin(pi/3)))
sqrt(3)
-------
2
pretty(sym(cos(pi)))
-1
pretty(sym(sin(0)))
0
pretty(sym(sin(2*pi)))
4967757600021511
- --------------------------------
20282409603651670423947251286016
pretty(sym(sin(2*sym(pi))))
0
trigonometry_with_symbolic
Give the desired angle:
'pi/4'
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym>convertCh
ar', 'C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m',
1537)" style="font-weight:bold">sym>convertChar</a> (<a href="matlab:
opentoline('C:\Program
Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m',1537,0)">line
1537</a>)
Character vectors and strings in the first argument can only specify a
variable or number. To evaluate character vectors and strings representing
symbolic expressions, use 'str2sym'.
Error in <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym>tomupad',
'C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m', 1253)"
style="font-weight:bold">sym>tomupad</a> (<a href="matlab: opentoline('C:\Program
Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m',1253,0)">line
1253</a>)
S = convertChar(x);
Error in <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym',
'C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m', 220)"
style="font-weight:bold">sym</a> (<a href="matlab: opentoline('C:\Program
Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m',220,0)">line 220</a>)
S.s = tomupad(x);
Error in <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('trigonometry_
with_symbolic', 'C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m', 5)"
style="font-weight:bold">trigonometry_with_symbolic</a> (<a href="matlab:
opentoline('C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m',5,0)">lin
e 5</a>)
angle = sym(input('Give the desired angle:\n'));}#
trigonometry_with_symbolic
Give the desired angle:
pi/4
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym/pretty')"
style="font-weight:bold">sym/pretty</a>
Too many output arguments.
Error in <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('trigonometry_
with_symbolic', 'C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m', 6)"
style="font-weight:bold">trigonometry_with_symbolic</a> (<a href="matlab:
opentoline('C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m',6,0)">lin
e 6</a>)
s = pretty(sym(sin(angle)));}#
trigonometry_with_symbolic
Give the desired angle:
pi/4
{#Error using <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('sym/pretty')"
style="font-weight:bold">sym/pretty</a>
Too many output arguments.
Error in <a
href="matlab:matlab.internal.language.introspective.errorDocCallback('trigonometry_
with_symbolic', 'C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m', 8)"
style="font-weight:bold">trigonometry_with_symbolic</a> (<a href="matlab:
opentoline('C:\Users\NOBIS\Documents\MATLAB\trigonometry_with_symbolic.m',8,0)">lin
e 8</a>)
disp(pretty(s))}#
trigonometry_with_symbolic
Give the desired angle:
pi/4
sqrt(2)
-------
2
sqrt(2)
-------
2
run trigonometry_with_symbolic
Give the desired angle:
pi
0
-1
trigonometry_with_symbolic
Give the desired angle:
pi/3
sqrt(3)
-------
2
1
-
2
trigonometry_with_symbolic
Give the desired angle:
0
\n
0
diary matlab_tutorial_01