1. clc
clear all
format short g
x=1,y=2
x =
1
y =
2
%%function call
f=Q0_01234567(x,y);
if it is like in below from reference
(1-x).^2+100*(y-x.^2).^2
ans =
100
if it is like in below from reference
output=(1-x).^2+100*(y-x.^2).^2;
disp(['Answer=' num2str(output)])
Answer=100
question 1 PART1
g = 9.8
g =
9.8
t=0:1:100;
d=Q1_01234567(t,g);
plot(t,d)
title('Distance travelled by a freely falling object');
xlabel('t (sec)');
ylabel('d (m) ');
1
2. PART 2
use of disp
disp(' t d')
t d
X=[t' d'];
disp(X);
0 0
1 4.9
2 19.6
3 44.1
4 78.4
5 122.5
6 176.4
7 240.1
8 313.6
9 396.9
10 490
11 592.9
12 705.6
13 828.1
14 960.4
15 1102.5
16 1254.4
2
6. 96.00 45158.40
97.00 46104.10
98.00 47059.60
99.00 48024.90
100.00 49000.00
TASK 2
%Part 1
A=[ 2 5 8 11 14 17
3 6 9 12 15 18
4 7 10 13 16 19
5 8 11 14 17 20
6 9 12 15 18 21]
A =
2 5 8 11 14 17
3 6 9 12 15 18
4 7 10 13 16 19
5 8 11 14 17 20
6 9 12 15 18 21
B= [5 10 15 20 25 30
30 35 40 45 50 55
55 60 65 70 75 80]
B =
5 10 15 20 25 30
30 35 40 45 50 55
55 60 65 70 75 80
v=[99 98 97 96 95 94 93 92 91]
v =
99 98 97 96 95 94 93 92 91
%replace the last four columns of the first and third rows of ? with the first four
%columns of the first two rows of ?
A([1 3], [end-3:end])
ans =
8 11 14 17
10 13 16 19
A([1 3], [end-3:end])=B([1 2], [1:4])
A =
2 5 5 10 15 20
3 6 9 12 15 18
4 7 30 35 40 45
5 8 11 14 17 20
6
7. 6 9 12 15 18 21
%replace the last four columns of the fourth row of ?
%with the elements 5 and 8 of ?
A([4], [1:4])=v([1],[5:8])
A =
2 5 5 10 15 20
3 6 9 12 15 18
4 7 30 35 40 45
95 94 93 92 17 20
6 9 12 15 18 21
%the last four columns of the fifth row of the
%? with columns 3 through 5 of the third row of ?
A([5], [1:4])=B([3], [3:6])
A =
2 5 5 10 15 20
3 6 9 12 15 18
4 7 30 35 40 45
95 94 93 92 17 20
65 70 75 80 18 21
PART B
A=[4 -2 6
2 8 2
6 10 3]
A =
4 -2 6
2 8 2
6 10 3
B=[8;4;0]
B =
8
4
0
X=inv(A)*B
X =
-1.8049
0.29268
2.6341
7
8. %for reference /practice only
function f=Q0_01234567(x,y)
%f=Q0_01234567(x,y)
f=(1-x).^2+100*(y-x.^2).^2;
end
%PART 1
% function of Part 1
function d=Q1_01234567(t,g)
d=(1/2)*g*t.^2;
end
8