Needs a MATLAB code. Exercise 2.6 solution A = rand(3) 0.814 0.913 0.278 0.905 0
ID: 3855563 • Letter: N
Question
Needs a MATLAB code.
Exercise 2.6 solution
A = rand(3)
0.814 0.913 0.278
0.905 0.632 0.546
0.127 0.097 0.957
A(1: size(A,1) + 1:end)
ans = 0.814 0.632 0.957
Prints out the diagnol elements of the matrix A.
Suppose x is a column vector. Compute, without using loops or conditionals, the matrix A given by a_ij = {1/(x_i - x_j)^2 if i plusminus j, 1 otherwise. (One way to do this uses direct assignment to the diagonal elements of A. Using row/column style indices, this is rather tricky, but sec Exercise 2.6.) Suppose A is any matrix. What does this statement do? A(1: size(A, 1) + 1: end)Explanation / Answer
x=rand(3,1); % For geting column vector x
A=zeros(3,3); % For initilization of A by zero
A(1: size(A,1) + 1:end)=1; % Assigining digonal vector
A(1,2)=1/((x(1,1)-x(2,1)).^2); % For first row
A(1,3)=1/((x(1,1)-x(3,1)).^2);
A(2,1)=1/((x(2,1)-x(1,1)).^2); % For second row
A(2,3)=1/((x(2,1)-x(3,1)).^2);
A(3,1)=1/((x(3,1)-x(1,1)).^2); % For third row
A(3,2)=1/((x(3,1)-x(2,1)).^2);
You can also solve the problem using index as matrix
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.