Write a simple MATLAB function to complete the following tas
Write a simple MATLAB function to complete the following task: The function includes three parameters: a vector C. a vector D. and n the number of elements in both vector C and D. The function called midDotp() returns the dot product of the two vectors. Write a simple MATLAB script to complete the following task: Write a sequence of steps to: Fill the vector C with numbers 1 to 10 in ascending order, Fill the vector D with the numbers 1 to 10 in descending order, Use the function midDotp() 2nd vectors C and D to compute the dot product, Print the result.
Solution
Solution for the Problem(C++)
Program :-
#include<iostream>
#include<vector>
using namespace std;
int midDotp(vector<int>& C,vector<int>& D)
{
int i,j;
cout<<\"The dot Product of Vector C and D\"<<endl;
for(i=1,j=10;i<=10,j>=1;i++,j--)
{
cout<<C[i]*D[j]<<\"\\t\"; //Dot product of the vector C and D.
}
}
int main()
{
int i;
vector<int> C(10);
vector<int> D(10);
vector<int> A(10);
for(i=1;i<=10;i++)
{
C[i]=i; //Assign values 1 to 10 to vector C.
}
for(i=10;i>=1;i--)
{
D[i]=i; //Assign values 10 to 1 to vector D.
}
midDotp(C,D); //passs vector C and D into midDotp function.
return 0;
}
Output :-
The dot Product of Vector C and D
10 18 24 28 30 30 28 24 18 10
