Purchase Solution

Coding in Matlab - Dot, cross, and triple products

Not what you're looking for?

Ask Custom Question

See the attached file.

The objective is to write MATLAB codes that calculate scalar, vector and triple (scalar) products of vectors.

Example: the scalar product function is R^3

Copy and paste the following programme into the MATLAB editor and save the program as scalar_prod.m

function z = scalar_prod(x,y) % clears all the variables from memory
z = 0; % initiate z
for i = 1:3; % loop
z = z+x(i)*y(i); % calculate each product and add it to the previous sum
end; % end the loop

To see an example of the use of the programme, return to the command window and type:
>> x = [1; 2; 3];
>> y = [-1; 1; 1];
>> scalar_prod(x; y)

You should see the answer:
>> ans = 4

Tasks

1. Write a function to calculate the scalar product of two vectors in R^4. Test your new function with the vectors x = [3;4;2;1] and y = [-2;3;4;5].

2. Write a function for calculating the cross product of two vectors in R^3. Test this function with the vectors x = [6;3;8] and y = [-3;2;-7].

3. Write a function for calculating the triple (scalar) product of three vectors in R^3. Test this function with the vectors x = [1;2;3], y = [-1;8;9] and z = [-2;3;4]. What is the MATLAB function, which allows a direct computation of a triple product?

Purchase this Solution

Solution Summary

This solution examines some basic vector operations in Matlab via working through the coding of dot and cross products.

Solution Preview

1. To find the scaler product of two vectors in R^4, we know each vector has exactly 4 entries. The Matlab code to extract the i-th entry for a vector x is x(i). So in your file scaler_prod.m, write:

function p=scaler_prod(x,y)
p=x(1)*y(1)+x(2)*y(2)+x(3)*y(3)+x(4)*y(4);

2. Now using the cross product formula of two vectors in R^3, in the file cross_prod.m, write:

function c=cross_prod(x,y)
c=zeros(3,1);
c(1)=x(2)*y(3)-y(3)*x(2);
...

Purchase this Solution


Free BrainMass Quizzes
Probability Quiz

Some questions on probability

Graphs and Functions

This quiz helps you easily identify a function and test your understanding of ranges, domains , function inverses and transformations.

Exponential Expressions

In this quiz, you will have a chance to practice basic terminology of exponential expressions and how to evaluate them.

Know Your Linear Equations

Each question is a choice-summary multiple choice question that will present you with a linear equation and then make 4 statements about that equation. You must determine which of the 4 statements are true (if any) in regards to the equation.

Geometry - Real Life Application Problems

Understanding of how geometry applies to in real-world contexts