given the matrix a = [ 1 -1 3; -1 2 5; 3 0 -4] and the vector b=[ 1; 0; -2], compute the column vector v storing the square of each element of the vector x in matlab

To compute the column vector v storing the square of each element of the vector x in Matlab, first we need to create the vector x by solving the system of linear equations Ax = b, where A is the matrix given and b is the vector given.

We can do this in Matlab using the backslash operator as follows:

A = [1 -1 3; -1 2 5; 3 0 -4];
b = [1; 0; -2];
x = A \ b; % solves Ax = b for x
79 chars
4 lines

Next, we can square each element of x using element-wise multiplication and store the result in a new column vector v:

v = x .^ 2; % element-wise square of x
39 chars
2 lines

The resulting vector v will store the square of each element of x.

related categories

gistlibby LogSnag