Professional Documents
Culture Documents
Introduction 9 - Amier-Qhaf J. Hiya-Hiya
Introduction 9 - Amier-Qhaf J. Hiya-Hiya
November 28,2022
BSME 3B
Computer Application
Introduction 9
f=
Inline function:
f(x)=x^2
diff(f) This command >>diff(f)
differentiates f with respect
to x
ans=
2*x
g=inline(‘sin(x)/cos(x),’x’) Make g as a new function
diff(g(x),x) This command >>diff(g(x), x)
differentiates the value of g
ans=
sin(x)^2/cos(x)^2+1
pretty(ans) Visualize the last equation 2
sin(x)
--------- +1
2
cos(x)
>>Derivative=inline(diff(f(x),x),’x’) The function that is being >>Derivative=inline(diff(f(x),x),’x’)
generated is the derivative
of the inline function that
was created, and an x also derivative=
functions as the new
function's independent
variable. Inline function:
derivative(x)= x.*2.0
>>g=inline(‘x^3-1’,’x’) Make g as a new function Inline function:
g(x)=x^3-1
>>derivative=inline(diff(g(x),x),’x’) Calculate its derivative and >>derivative=inline(diff(g(x),x),’x’)
put into new function
deriv=
Inline function:
deriv(x)=x.^2.*3.0
>>syms x Function x and y as a >>syms x
variable
>>syms y >>syms y
>>f=inline(‘sin(x)+y^3,’x’,’y’) >>f=inline(‘sin(x)+y^3,’x’,’y’)
f=
Inline function:
f(x,y)=sin(x)+y^3
>>diff(f(x,y),x) Taking the derivative with >>diff(f(x,y),x)
respect to x
ans=
cos(x)
>>diff(f(x,y),y) Taking the derivative with >>diff(f(x,y),y)
respect to y
ans=
3*y^2
Inline functions:
h(x,y,z)=x^10-y^2+log(z)
>>diff(h(x,y,z),x Using x as the variable on >>diff(h(x,y,z),x
which to compute the
derivative makes all other
variables constant. ans=
10*x^9
>>f = int(expr) computes the indefinite >>f = int(expr)
integral of expr. int uses
the default integration
variable determined by f=
(expr,1). If expr is a
constant, then the default 1x2+1
integration variable is x.
fx(x, z) =
x22 (z2+1)
>>syms x computes the definite >>syms x
integral
>>expr = x*log(1+x); >>expr = x*log(1+x);
of expr from a to b. int uses
>>F = int(expr,[0 1]) the default integration >>F = int(expr,[0 1])
variable determined
by (expr,1). If expr is a
constant, then the default f=
integration variable is x.
1/4
jason=
Inline function:
jason(x)=x^2
>>syms x Taking the limit of the >>syms x
function defined
>>limit(jason(x),x,5) >>limit(jason(x),x,5)
ans=
25
>>scatter( x , y ) scatter( x , y ) creates a
scatter plot with circular
markers at the locations
specified by the vectors x
and y.To plot one set of
coordinates, specify x and
y as vectors of equal
length. To plot multiple
sets of coordinates on the
same set of axes, specify at
least one of x or y as a
matrix.
>>grid on and grid on adds major grid
lines to the current axes.
>>grid off