0% found this document useful (0 votes)
70 views4 pages

For If Elseif Else End End

This document contains the results of Vibrations HW 13. It finds the roots of two functions, cos(x)cosh(x)-1 and cos(x), denoted as x1 and x2, respectively. It calculates the roots for increasing values of x up to 48, and computes the error between x1 and x2. The roots and corresponding errors are written to a file called vibrationhw13.txt.

Uploaded by

Nick Estrada
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views4 pages

For If Elseif Else End End

This document contains the results of Vibrations HW 13. It finds the roots of two functions, cos(x)cosh(x)-1 and cos(x), denoted as x1 and x2, respectively. It calculates the roots for increasing values of x up to 48, and computes the error between x1 and x2. The roots and corresponding errors are written to a file called vibrationhw13.txt.

Uploaded by

Nick Estrada
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

12).

%Hw 13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;
format long
p(1)=fzero('fun',4);
i=1;
for x=4:30
p(i+1)=fzero('fun',x);
if p(i+1)<=p(i)
i=i;
elseif round(tanh(p(i+1))/tan(p(i+1)))~=1
i=i;
else
i=1+i;
end;
end
q(1)=fzero('fun1',1);
j=1;
for x=1:30
q(j+1)=fzero('fun1',x);
if q(j+1)<=q(j)
j=j;
elseif round(tan(q(j+1)))~=1
j=j;
else
j=1+j;
end;
end;
for k=1:10
L=k+1
e(k)=abs(p(k)-q(L))/p(k)*100
end;
fid=fopen('vibrationhw12.txt','w');
fprintf(fid,' Vibrations HW 12\n');
fprintf(fid,' \n');
fprintf(fid,'x1 is just tan(x)/tanh(x)-1=0 \n');
fprintf(fid,'x2 is just tan(x)=1 \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,'
#
x1
x2
error %\n');
fprintf(fid,' \n');
fprintf(fid,'-------------------------------------------------------- \n');
j=1;
fprintf(fid,' %3.0f
%3.4f
---------------- \n',j,q(j)');
for i=1:10
j=i+1;
fprintf(fid,' %3.0f
%3.4f
%3.4f
%0.25f \n',j,p(i),q(j),e(i));
end
%fun.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=fun(x)
f=tan(x)/tanh(x)-1

%func1.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=fun1(x)
f=tan(x)-1;

Vibrations HW 12
x1 is just tan(x)/tanh(x)-1=0
x2 is just tan(x)=1

#
x1
x2
error
---------------------------------------------------------1
0.7854
--------------------------2
3.9266
3.9270
0.0098941758917324325000000
3
7.0686
7.0686
0.0000102559215668212010000
4
10.2102
10.2102
0.0000000132592920842851320
5
13.3518
13.3518
0.0000000000189319918921765
6
16.4934
16.4934
0.0000000000000215402645094
7
19.6350
19.6350
0.0000000000000000000000000
8
22.7765
22.7765
0.0000000000000000000000000
9
25.9181
25.9181
0.0000000000000000000000000
10
29.0597
29.0597
0.0000000000000000000000000
11
29.8451
29.8451
0.0000000000000000000000000

13).
%Hw 13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;
format long
p(1)=fzero('func',2);
i=1;
for x=2:2:48
p(i+1)=fzero('func',x);
if p(i+1)<=p(i)
i=i;
elseif abs(p(i+1)-p(i))<1E-15
i=i;
else
i=1+i;
end;
end
q(1)=fzero('func1',1);
j=1;
for x=1:48
q(j+1)=fzero('func1',x);
if q(j+1)<=q(j)
j=j;
elseif abs(q(j+1)-q(j))<1E-14
j=j;
else
j=1+j;
end;
end;
for k=1:15
L=k+1
e(k)=abs(p(k)-q(L))/p(k)*100
end;
fid=fopen('vibrationhw13.txt','w');
fprintf(fid,' Vibrations HW 13\n');
fprintf(fid,' \n');
fprintf(fid,'x1 is just cos(x)cosh(x)-1=0 \n');
fprintf(fid,'x2 is just cos(x)=0 \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,' \n');
fprintf(fid,'
#
x1
x2
error %\n');
fprintf(fid,' \n');
fprintf(fid,'-------------------------------------------------------- \n');
j=1;
fprintf(fid,' %3.0f
%3.4f
---------------- \n',j,q(j)');
for i=1:15
j=i+1;
fprintf(fid,' %3.0f
%3.4f
%3.4f
%0.20f \n',j,p(i),q(j),e(i));
end
%func.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=func(x)
f=cosh(x)*cos(x)-1;

%func1.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=func1(x)
f=cos(x);

Vibrations HW 13
x1 is just cos(x)cosh(x)-1=0
x2 is just cos(x)=0

#
x1
x2
error
----------------------------------------------------1
1.5708
---------------------2
4.7300
4.7124
0.37318419502380956000
3
7.8532
7.8540
0.00989417589172112210
4
10.9956
10.9956
0.00030512580924552834
5
14.1372
14.1372
0.00001025592157938636
6
17.2788
17.2788
0.00000036261639752556
7
20.4204
20.4204
0.00000001325930948219
8
23.5619
23.5619
0.00000000049658494994
9
26.7035
26.7035
0.00000000001893199189
10
29.8451
29.8451
0.00000000000073803748
11
32.9867
32.9867
0.00000000000002154026
12
36.1283
36.1283
0.00000000000001966720
13
39.2699
39.2699
0.00000000000000000000
14
42.4115
42.4115
0.00000000000000000000
15
45.5531
45.5531
0.00000000000001559812
16
48.6947
48.6947
0.00000000000001459179

You might also like