Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Function: % (Root Finding With Rootsearch)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

1.

function y= fex41_3(x)
y = cosh(x)*cos(x) - 1;

root = brent(@fex41_3,4,5)
>> nomor3
root =
4.7300

2. function y=fex41_4(x)
y= cosh(x)*cos(x) - 1;

function y= dfex_4(x)
y= sinh(x)*sin(x);

root = newtonRaphson(@fex41_4,@dfex41_4,4,5)
>> nomor4
root =
4.7300

3. function y =fex41_11(x)
y= x*sin(x) + 3*cos(x) - x;

function y =dfex41_11(x)
y= x*cos(x) - 3*sin(x) - 1;

root = newtonRaphson(@fex41_11,@ dfex41_11,-6,6)


>> nomor11
root =
1.5708

4. function y= fex41_12(x)
y= x*4 + 0.9*x^3 - 2.3*x^2 + 3.6*x - 25.2;

%(root finding with rootsearch)


a = 0.0; b = 50; dx = 0.01;
nroots = 0;
while 1
[x1,x2] = rootsearch(@fex41_12,a,b,dx);
if isnan(x1)
break
else
a = x2;
x = bisect(@fex41_12,x1,x2,1);
if ~isnan(x)
nroots = nroots + 1;
root(nroots) = x;
end
end
end
root
>> nomor12
root =
2.9322

5. % Matlab
x = [2.36, 2.37, 2.38, 2.39];
y = [0.85866, 0.86289, 0.86710, 0.87129];
a = (-3*y(1)+4*y(2)-y(3))/(0.01*2);
b = (2*y(1)-5*y(2)+4*y(3)-y(4))/((0.01)^2);
f(2.26) = a
= 0.4240
f(2.36) = b
= -0.2000

% Manual
x 2.36 2.37 2.38 2.39

f(x) 0.85866 0.86289 0.86710 0.87129


f(2.36) = (-3*f(2.36)+4*f(2.37)-f(2.38))/(2*0.01)
= (-3*(0.85866)+4*(0.86289)-(0.86710))/(2*0.01)
= 0.4240
f(2.36) = (2*f(2.36)-5*f(2.37)+4*f(2.38)-f(2.39))/((0.01)^2)
= (2*f(0.85866)-5*f(0.86289)+4*f(0.86710)-(0.87129))
/((0.01)^2)
= -0.2000
6. % Matlab
x =[0.95, 1.00, 1.05];
y =[0.85040, 0.84147, 0.82612];
a =(-y(1)+y(3))/(2*0.5)
b =(y(1)-2*y(2)+y(3))/(0.5^2)
% f(1.0) = a
% f(1.0)= b
>> jawaban_no_6
f(1.0) = -0.2428
f(1.0) = -2.5680

% Manual
x 0.95 1.00 1.05

f(x) 0.85040 0.84147 0.82612


f(1.0) = (-f(0.95)+f(1.05))/(2*0.05)
= (-(0.85040)+(0.82612))/(2*0.05)
= -0.2428
f(1.0) = (f(2.36)-2*f(2.37)+f(2.38))/(0.05^2)
= ((0.85040)-2*(0.84147)+(0.82612))/(0.05^2)
= -2.5680
7. % Matlab
x =[0.84, 0.92, 1.00, 1.08, 1.16];
y =[0.431711, 0.398519, 0.367879, 0.339596, 0.313486];
a =(y(1)-2*y(3)+y(5))/(0.16^2);
b =(y(2)-2*y(3)+y(4))/(0.08^2);
f =(4*b-a)/3
% f(1)= f
>> jawaban_no_7
f(1) = 0.3681

% Manual
x 0.84 0.92 1.00 1.08 1.16

f(x) 0.431711 0.398519 0.367879 0.339596 0.313486

G(0.08) = (f(1.00)-2*f(1.00)+f(1.16))/(0.16^2)
= (f(0.431711)-2*f(0.367879)+f(0.313486))/(0.16^2)
= 0.3687
G(0.08) = (f(0.92)-2*f(1.00)+f(1.08))/(0.08^2)
= (f(0.398519)-2*f(0.367879)+f(0.339596))/(0.08^2)
= 0.3683
f(1.0)= (4*G(0.08)-G(0.16))/3
= (4*(0.3683)-G(0.3687))/3
= 0.3681

8. % Matlab
x = [0, 0.1, 0.2, 0.3, 0.4];
y = [0.000, 0.078348, 0.138910, 0.192916, 0.244981];
a = (-y(1)+y(5))/(2*0.2);
b = (-y(2)+y(4))/(2*0.1);
f = (4*b-a)/3
% f(0.2)= f
>> jawaban_no_8
f(0.2)= 0.5596

% Manual
x 0 0.1 0.2 0.3 0.4

f(x) 0.000 0.078348 0.138910 0.192916 0.244981

G(0.2) = (-f(0)+f(0.4))/(0.2^2)
= (-(0.000)+(0.244981))/(2*0.2)
= 0.6125
G(0.1) = (-f(0.1)+f(0.3))/(0.1^2)
= (-(0.078348)+(0.192916))/(2*0.1)
= 0.5728
f(1.0)= (4*G(0.1)-G(0.2))/3
= (4*(0.5728)-G(0.6125))/3
= 0.5596

9. function y = fex_no_9(x)
y = log(1 + tan(x));

% (Recursive trapezoidal rule)


format long % Display extra precision
I2h = 0;
for k = 1:20
Ih = trapezoid(@fex_no_9,0,(pi/4),I2h,k);
if (k > 1 & abs(Ih - I2h) < 1.0e-6)
Integral = Ih
No_of_func_evaluations = 2^(k-1) + 1
return
end
I2h = Ih;
end
error('Too many iterations')
>> jawabann_no_9
Integral = 0.272198261287950
No_of_func_evaluations = 3

10. x =[0.00 0.05 0.10 0.15 0.20 0.25 ...


0.30 0.35 0.40 0.45 0.50];
y =[0 37 71 104 134 161 ...
185 207 225 239 250];
m =0.075;
I =(y(1)+4*y(2)+2*y(3)+4*y(4)+2*y(5)+4*y(6)+2*y(7)+4*y(8)+
2*y(9)+4*y(10)+y(11)) *(0.05/3);
V=sqrt(I*2/m)
>> jawaban_no_10
v =
44.5820

11.function y = fex_no_11(x)
y = x*5 + 3*x^3 - 2;

format long
[Integral,numEval] = romberg(@fex_no_11,0,2)

>> jawaban_no_11
Integral =
18
numEval =
5
12. x =[0, (pi/4), (pi/2), (3*pi/4), (pi)];
y =[1.0000 0.3431 0.2500 0.3431 1.0000];
I =(y(1)+4*y(2)+2*y(3)+4*y(4)+y(5))*((1/4)/3)
% Integral = I
>> jawaban_no_12
I =
0.4371

% Manual
x 0 /4 /2 3/4

f(x) 0.000 0.078348 0.138910 0.192916 0.244981



I = [f(0)+4*f(/4)+2*f(/2)+4*f(3/4)+f()]3
1
= [(0.00)+4*(0.078348)+2*(0.138910)+4*(0.192916)+(0.244981)] 12

= 0.4371

You might also like