Академический Документы
Профессиональный Документы
Культура Документы
[fmin,i]=min(fval);
xmin=x(i);
disp(['Min value: ',num2str(fmin), ', at
x=',num2str(xmin)]);
[fmax,i]=max(fval);
xmax=x(i);
disp(['Max value: ',num2str(fmax), ', at x=',num2str(xmax)]);
Explanation:
Note that x(2:2:n) gives all even-numbered terms of vector x.
Likewise, x(1:2:n) will give all odd-numbered terms.
For funVal, we note that 1:n yields a vector, which when multiplied with x gives:
1*x(1) + 2*x(2) + so.on...
Results
For the vector: x1=[7, 1, 4, 8, 7, 9, 6]:
3&4: evenSum: 18; funVal: 184
For the vector x2:
5&6: evenSum: -1.3442; funVal: -3.8729
Problem 3: Matrix Problem
For the given matrix:
Please try out the commands and you will get the results
>> sum(A(1:2:end,1))
ans =
0
>> rank(A(1:2,2:4))
ans =
2
>> b = A(2,2:5)
b =
1 3 -2 1
>> B = B = A(3:4,1:2)
B =
-1 0
-3 2
4 (b)
0.5 (a) Error
2
0 0
0 0.2 0.4 0.6 0.8 1 0 1 2 3 4
6 6
4 (c) 4 (d)
2 2
0 0
0 1 2 3 4 0 1 2 3 4
6 6
4 (e) 4 (f)
2 2
0 0
0 1 2 3 4 0 1 2 3 4
The plots shown above clearly indicate that (d) and (e) are the right answers.