test1
{Error: File: test1.m Line: 10 Column: 38
Unbalanced or unexpected parenthesis or bracket.}
test1
Please enter your name: Leon van Dommelen
{Error using test1 (line 1)
Error: Unexpected MATLAB expression.}
Please enter your name: {Operation terminated by user during test1 (line 1)
}
test1
Please enter your name: Leon van Dommelen
choice =
1
choice =
2
choice =
0
choice =
3
choice =
4
test2
x =
1
expValue =
2.7183
expError =
0
% symbolic computations
qNum=@(x) -4*x.^2+3*x+12;
qInt02=integral(qNum,0,2)
qInt02 =
19.3333
qNumRoot=fzero(qNum,1)
qNumRoot =
2.1472
syms x
qSym=-4*x^2+3*x+12
qSym =
- 4*x^2 + 3*x + 12
qSymInt02=int(qSym,x,[0 2])
qSymInt02 =
58/3
qSymInt=int(qSym,x)
qSymInt =
(x*(- 8*x^2 + 9*x + 72))/6
expand(qSymInt)
ans =
- (4*x^3)/3 + (3*x^2)/2 + 12*x
qSymDiff=diff(qSym,x)
qSymDiff =
3 - 8*x
qSymDiff=diff(qSym)
qSymDiff =
3 - 8*x
qSymInt=int(qSym)
qSymInt =
(x*(- 8*x^2 + 9*x + 72))/6
sympar(qSym)
{Undefined function or variable 'sympar'.}
symvar(qSym)
ans =
x
qSymRoots=solve(qSym == 0,x)
qSymRoots =
3/8 - 201^(1/2)/8
201^(1/2)/8 + 3/8
double(qSymRoots)
ans =
-1.3972
2.1472
qSymFactors=factor(qSym)
qSymFactors =
[ -1, 4*x^2 - 3*x - 12]
help factor
factor Prime factors.
factor(N) returns a vector containing the prime factors of N.
This function uses the simple sieve approach. It may require large
memory allocation if the number given is too big. Technically it is
possible to improve this algorithm, allocating less memory for most
cases and resulting in a faster execution time. However, it will still
have problems in the worst case.
Class support for input N:
float: double, single
integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64
See also primes, isprime.
Reference page for factor
Other functions named factor
matlab.internal.language.introspective.overloads.displayOverloads('factor')
sym/factor
help sym/factor
factor Symbolic factorization.
factor(S), where S is a SYM, returns all irreducible factors of S.
If S is an integer, the prime factorization is computed.
To factor an integer N greater than 2^52, use factor(SYM('N')).
factor(S, VARS), where VARS is a vector of variables,
returns all irreducible factors of S, but does not split factors
that do not contain VARS.
factor(S, 'FACTORMODE', MODE) or
factor(S, VARS, 'FACTORMODE', MODE)
factors S in the factorization mode MODE.
The modes differ only in the case of univariate polynomials.
Possible values:
'rational' - rational factorization.
Result can contain only those irrational subexpressions
that occur already in the input.
This is the default mode.
'full' - factor into symbolic linear factors.
'complex' - factor numerically into linear factors.
'real' - factor numerically into linear or quadratic real factors.
Examples:
factor(x^9-1) is
[x - 1, x^2 + x + 1, x^6 + x^3 + 1]
factor(sym('12345678901234567890')) is
[2, 3, 3, 5, 101, 3541, 3607, 3803, 27961]
factor(x^2 * y^2, x) is
[y^2, x, x]
factor(x^2 + 1, 'FactorMode', 'rational') is
[x^2 + 1]
factor(x^2 + 1, 'FactorMode', 'full') is
[x - 1i, x + 1i]
See also factor, sym/simplify, sym/expand, sym/collect, sym/partfrac.
qSymFactors=factor(qSym,x,'FactorMode','full')
qSymFactors =
[ -1, x + 201^(1/2)/8 - 3/8, x - 201^(1/2)/8 - 3/8]
prod(qSymFactors)
ans =
(x + 201^(1/2)/8 - 3/8)*(201^(1/2)/8 - x + 3/8)
629/969
ans =
0.6491
simplify(629/969)
{Undefined function 'simplify' for input arguments of type
'double'.}
simplify(sym('629/969'))
ans =
37/57
% very high accuracy
pi^6/6
ans =
160.2315
pi^2/6
ans =
1.6449
vpa(pi^2/6,50)
ans =
1.6449340668482264060656916626612655818462371826172
vpa(sym('pi^2/6'),50)
ans =
1.6449340668482264364724151666460251892189499012068
Solving equations
{Undefined function or variable 'Solving'.}
% Solving equations
syms x a b c qGen
qGen=a*x^2+b*x+c
qGen =
a*x^2 + b*x + c
qGenRoots=solve(qGen == 0,x)
qGenRoots =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
pretty(qGenRoots)
/ 2 \
| b + sqrt(b - 4 a c) |
| - -------------------- |
| 2 a |
| |
| 2 |
| b - sqrt(b - 4 a c) |
| - -------------------- |
\ 2 a /
qGenRootsTest=subs(qGenRoots,{a b c},{-4 3 12})
qGenRootsTest =
201^(1/2)/8 + 3/8
3/8 - 201^(1/2)/8
qGenRootsFun=matlabFunction(qGenRoots)
qGenRootsFun =
@(a,b,c)[(b.*(-1.0./2.0)-sqrt(a.*c.*-4.0+b.^2).*(1.0./2.0))./a;(b.*(-1.0./2.0)+sqrt(a.*c.*-4.0+b.^2).*(1.0./2.0))./a]
qGenRootsFun(-4,3,12)
ans =
2.1472
-1.3972
% solving non-polynomial equations
syms x y
solve(exp(x) == -1,x)
ans =
pi*1i
qxySym=a*x*y-b*x-1
qxySym =
a*x*y - b*x - 1
solve(a*x*y-b*x-1)
ans =
-1/(b - a*y)
symvar(qxySym)
ans =
[ a, b, x, y]
symvar(qxySym,3)
ans =
[ x, y, b]
symvar(qxySym == 0,x)
{Error using symengine
DOUBLE cannot convert the input expression into a double
array.
If the input expression contains a symbolic variable, use VPA.
Error in sym/double (line 588)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in sym/symvar (line 31)
n = double(n);}
solve(qxySym == 0,x)
ans =
-1/(b - a*y)
solve(qxySym == 0,y)
ans =
(b*x + 1)/(a*x)
xCoefs=collect(qxySym,x)
xCoefs =
(a*y - b)*x - 1
ratPartFrac=(2x^2-3*x+1)/(x^3+2*x^2-9*x-18)
ratPartFrac=(2x^2-3*x+1)/(x^3+2*x^2-9*x-18)
{Error: Unexpected MATLAB expression.
}
ratPartFrac=(2*x^2-3*x+1)/(x^3+2*x^2-9*x-18)
ratPartFrac =
-(2*x^2 - 3*x + 1)/(- x^3 - 2*x^2 + 9*x + 18)
factor(ratPartFrac)
ans =
[ 2*x - 1, x - 1, 1/(x - 3), 1/(x + 3), 1/(x + 2)]
partfrac(ratPartFrac)
ans =
1/(3*(x - 3)) - 3/(x + 2) + 14/(3*(x + 3))
intHard1=int(1/(x*(a*x^2+b*x+c)^(1/2)))
intHard1 =
-log(b/2 + c/x + (c^(1/2)*(a*x^2 + b*x + c)^(1/2))/x)/c^(1/2)
intHard1=int(1/(x*(a*x^2+b*x+c)^(3/2)))
intHard1 =
int(1/(x*(a*x^2 + b*x + c)^(3/2)), x)