Sie sind auf Seite 1von 8

Annas Khan

20458375
Lab 3
Task 1. A
function [det_A,x]=solvexf(r)
%SolveXF solves a 3x3 matrix equation with parameter r
%This is the fn file 'solvexf.m'
%r is the input nad det_A and x are outputs
%-----------------------------------------A=[5 2*r r; 3 6 2*(r-1); 2 r-1 3*r]; %create matrix A
b=[2;3;5];
%create vector b
det_A=det(A);
%find the determinant
x=A\b;
%find x

Task 1.b
solvexf(1)
ans =
60
Task 1.c
Did you mean:
>> det_A
Undefined function or variable 'det_A'.
Did you mean:
>> x
Undefined function or variable 'x'.
>> r
Undefined function or variable 'r'.
They are not in the workspace since the mentioned variables are local, meaning they are confined to the
.m file. Therefore they cannot be accessed from the workspace.
Task 2.a
function a=hypersum(x)
%HYPERSUM gives the sum of tanh(x) and cosh(x)
%This is the function file `hypersum.m`
%x is the input and a is the output
%--------------------------------------------a=tanh(x) + cosh(x);

Task 2.b

hypersum(2) %take x=2 and execute hypersum.m


ans =
4.7262
Task 2.C
>> sqrt(3) + hypersum(4) % take x=4, execute hypersum.m & add sqrt(3)
ans =
30.0396
>> sin(pi/4) + hypersum(6) % take x=6, execute hypersum.m & add sin(pi/4)
ans =
203.4227
Exercise 1
A)
celcius2fheit(30,50)
ans =
30.0000
31.0000
32.0000
33.0000
34.0000
35.0000
36.0000
37.0000
38.0000
39.0000
40.0000
41.0000
42.0000
43.0000
44.0000
45.0000
46.0000
47.0000
48.0000
49.0000
50.0000
B)

86.0000
87.8000
89.6000
91.4000
93.2000
95.0000
96.8000
98.6000
100.4000
102.2000
104.0000
105.8000
107.6000
109.4000
111.2000
113.0000
114.8000
116.6000
118.4000
120.2000
122.0000

celcius2fheit(-30,0)
ans =
-30.0000 -22.0000
-29.0000 -20.2000
-28.0000 -18.4000
-27.0000 -16.6000
-26.0000 -14.8000
-25.0000 -13.0000
-24.0000 -11.2000
-23.0000 -9.4000
-22.0000 -7.6000
-21.0000 -5.8000
-20.0000 -4.0000
-19.0000 -2.2000
-18.0000 -0.4000
-17.0000 1.4000
-16.0000 3.2000
-15.0000 5.0000
-14.0000 6.8000
-13.0000 8.6000
-12.0000 10.4000
-11.0000 12.2000
-10.0000 14.0000
-9.0000 15.8000
-8.0000 17.6000
-7.0000 19.4000
-6.0000 21.2000
-5.0000 23.0000
-4.0000 24.8000
-3.0000 26.6000
-2.0000 28.4000
-1.0000 30.2000
0 32.0000
C)
A=celcius2fheit(30,50)
>> Tc=A(:,1);
>> Tf=A(:,2);
>> table=[Tc';Tf'];
file_id =fopen('temperature.dat','wt')
file_id =
25
>> fprintf(file_id, '%3.2f %3.2f\n', table)
ans =
265

30.00 86.00
31.00 87.80
32.00 89.60
33.00 91.40
34.00 93.20
35.00 95.00
36.00 96.80
37.00 98.60
38.00 100.40
39.00 102.20
40.00 104.00
41.00 105.80
42.00 107.60
43.00 109.40
44.00 111.20
45.00 113.00
46.00 114.80
47.00 116.60
48.00 118.40
49.00 120.20
50.00 122.00
D)
B=importdata('temperature.dat')
B=
30.0000
31.0000
32.0000
33.0000
34.0000
35.0000
36.0000
37.0000
38.0000
39.0000
40.0000
41.0000
42.0000
43.0000
44.0000

86.0000
87.8000
89.6000
91.4000
93.2000
95.0000
96.8000
98.6000
100.4000
102.2000
104.0000
105.8000
107.6000
109.4000
111.2000

45.0000
46.0000
47.0000
48.0000
49.0000
50.0000

113.0000
114.8000
116.6000
118.4000
120.2000
122.0000

Tf=B(:,2)
Tf =
86.0000
87.8000
89.6000
91.4000
93.2000
95.0000
96.8000
98.6000
100.4000
102.2000
104.0000
105.8000
107.6000
109.4000
111.2000
113.0000
114.8000
116.6000
118.4000
120.2000
122.0000
TR=Tf+459.67
TR =
545.6700
547.4700
549.2700
551.0700
552.8700
554.6700
556.4700
558.2700
560.0700
561.8700
563.6700
565.4700

567.2700
569.0700
570.8700
572.6700
574.4700
576.2700
578.0700
579.8700
581.6700
>> table=[Tc';Tf';TR'];
>> file_id =fopen('temptable.dat','wt')
file_id =
27
>> fprintf(file_id, '%3.2f %3.2f %3.2f\n', table)
ans =
412

30.00 86.00 545.67


31.00 87.80 547.47
32.00 89.60 549.27
33.00 91.40 551.07
34.00 93.20 552.87
35.00 95.00 554.67
36.00 96.80 556.47
37.00 98.60 558.27
38.00 100.40 560.07
39.00 102.20 561.87
40.00 104.00 563.67
41.00 105.80 565.47
42.00 107.60 567.27
43.00 109.40 569.07
44.00 111.20 570.87
45.00 113.00 572.67
46.00 114.80 574.47
47.00 116.60 576.27
48.00 118.40 578.07

49.00 120.20 579.87


50.00 122.00 581.67
Exercise 2
function [x,i] = interest(xnot,n,r,k)
%This function calculates the interest rate
x=xnot*(1+(r/k))^(k*n)
i=x-xnot

i)
interest(10000,5,0.06,4)
x=
13468.55
i=
3468.55
%x is principal and I is interest
ii)
>> interest(10000,5,0.06,365)
x=
13498.26
i=
3498.26
%x is principal and I is interest
Exercise 3
function [T] = temp(Ti,To,Tow,time)
%This function calculates the ball temperature
T=(Ti-To)*exp(-time/Tow)+To

>> temp(1000,60,60,[0.1,10,100])
T=
998.43

855.69

237.54

Das könnte Ihnen auch gefallen