myFun = @(x) x.*exp(-x/2)
f = @(x) sin(x)+x.^2;
y = f(2)
fplot(f,[-2 2]);
fun1 = @(x) 0.5 - sin(x)
fplot(fun1,[-1 1])
fun2 = @(x) x.^2
hold on
fplot(fun2, [-1 1])
rootFunction = @(x) cos(x) - x
brackets = [1.5 0];
x = fzero(rootFunction,brackets)
x =
0.7391
rootFunction = @(x) cos(x) - x;
xApprox = 1;
xApprox = 1;
x = fzero(rootFunction,xApprox)
x =
0.7391
rootFunction = @(x) 0.5-sin(x)-x^2
fplot(rootFunction, [-1 1])
x0 = [0 0.5]
x = fzero(rootFunction, x0)
y = rootFunction(x)
plot(x,y,'o')
rootFunction = @(x) 0.5-sin(x)-x.^2;
fplot(rootFunction,[-2 1]);
hold on
plot([-2 1],[0 0]);
hold off
grid on
% previous provided code
rootFunction = @(x) 0.5-sin(x)-x.^2;
fplot(rootFunction,[-2 1]);
hold on
plot([-2 1],[0 0]);
hold off
grid on
% find the root near x = -1
bracket1 = [-1.5 -1]
xRoot1 = fzero(rootFunction, bracket1)
% visualize the root
yRoot1 = rootFunction(xRoot1);
hold on
plot(xRoot1,yRoot1,'om');
hold off
bracket2 = [0 0.5]
xRoot2 = fzero(rootFunction, bracket2)
% previous provided file and code
load electricityData.mat
elecFun = @(x) -0.000537*x.^3 + 0.00926*x.^2 + 0.1526.*x + 7.418 - 10;
% plot time and usage - 10
plot (time, usage -10)
x0 = [13.9 15.9]
x = fzero(elecFun,x0)
fun38 = @(x) x.^3-8
% if fun38 = @(x) x^3-8 must be err: The left input to the subtraction operator was
% expected to be anonymousInput1 .^3.
fplot(fun38, [-5 5])
grid on
x0 = [0 5] % by showing plot, we can put the interval of fun38
root38 = fzero(fun38, x0)
myFun = @(x) x.*exp(-x/2)
f = @(x) sin(x)+x.^2;
y = f(2)
fplot(f,[-2 2]);
fun1 = @(x) 0.5 - sin(x)
fplot(fun1,[-1 1])
fun2 = @(x) x.^2
hold on
fplot(fun2, [-1 1])
rootFunction = @(x) cos(x) - x
brackets = [1.5 0];
x = fzero(rootFunction,brackets)
x =
0.7391
rootFunction = @(x) cos(x) - x;
xApprox = 1;
xApprox = 1;
x = fzero(rootFunction,xApprox)
x =
0.7391
rootFunction = @(x) 0.5-sin(x)-x^2
fplot(rootFunction, [-1 1])
x0 = [0 0.5]
x = fzero(rootFunction, x0)
y = rootFunction(x)
plot(x,y,'o')
rootFunction = @(x) 0.5-sin(x)-x.^2;
fplot(rootFunction,[-2 1]);
hold on
plot([-2 1],[0 0]);
hold off
grid on
% previous provided code
rootFunction = @(x) 0.5-sin(x)-x.^2;
fplot(rootFunction,[-2 1]);
hold on
plot([-2 1],[0 0]);
hold off
grid on
% find the root near x = -1
bracket1 = [-1.5 -1]
xRoot1 = fzero(rootFunction, bracket1)
% visualize the root
yRoot1 = rootFunction(xRoot1);
hold on
plot(xRoot1,yRoot1,'om');
hold off
bracket2 = [0 0.5]
xRoot2 = fzero(rootFunction, bracket2)
% previous provided file and code
load electricityData.mat
elecFun = @(x) -0.000537*x.^3 + 0.00926*x.^2 + 0.1526.*x + 7.418 - 10;
% plot time and usage - 10
plot (time, usage -10)
x0 = [13.9 15.9]
x = fzero(elecFun,x0)
fun38 = @(x) x.^3-8
% if fun38 = @(x) x^3-8 must be err: The left input to the subtraction operator was
% expected to be anonymousInput1 .^3.
fplot(fun38, [-5 5])
grid on
x0 = [0 5] % by showing plot, we can put the interval of fun38
root38 = fzero(fun38, x0)
myFun = @(x) x.*exp(-x/2)