Question

Prepare a MATLAB program (script file) that allows a user to enter two 4-element vectors and...

Prepare a MATLAB program (script file) that allows a user to enter two 4-element vectors and scalar values to perform different mathematical (exponentiation, multiplication, and subtraction) operations on the elements within the originally entered vectors Moreover, the program also performs addition, dot product and element-wise multiplication of the two vectors.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB CODE

clc;
V1=input('Enter 4-element Vector 1 : ');
V2=input('Enter 4-element Vector 2 : ');
S=input('Enter Scaler : ');
%% exponentiation
disp('Vectors After exponentiation is ');
V1_exp=S.^V1
V2_exp=S.^V2
%% Multiplication
disp('Vectors After Multiplication is ');
V1_Mul=S.*V1
V2_Mul=S.*V2
%% Subtraction
disp('Vectors After Subtraction is ');
V1_Sub=V1-S
V2_Sub=V2-S
%% Vector Addition
disp('Vectors After Addition of Both Vectors is ');
V_Add=V1+V2
%% Vector Multiplication
disp('Vectors After Multiplication of Both Vectors is ');
V_Mul=V1.*V2
%% Dot Product
disp('Vectors After Dot Product of Both Vectors is ');
V_Dot=dot(V1,V2)


Results:

Enter 4-element Vector 1 : [4 1 3 1]
Enter 4-element Vector 2 : [4 5 1 6]
Enter Scaler : 4
Vectors After exponentiation is
V1_exp =
256 4 64 4
V2_exp =
256 1024 4 4096
Vectors After Multiplication is
V1_Mul =
16 4 12 4
V2_Mul =
16 20 4 24
Vectors After Subtraction is
V1_Sub =
0 -3 -1 -3
V2_Sub =
0 1 -3 2
Vectors After Addition of Both Vectors is
V_Add =
8 6 4 7
Vectors After Multiplication of Both Vectors is
V_Mul =
16 5 3 6
Vectors After Dot Product of Both Vectors is
V_Dot =
30

Add a comment
Know the answer?
Add Answer to:
Prepare a MATLAB program (script file) that allows a user to enter two 4-element vectors and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • matlab progam A commonly used matrix operation in linea alpebrais matrix matrix multiplication. Write a script...

    matlab progam A commonly used matrix operation in linea alpebrais matrix matrix multiplication. Write a script that reads a matrix M from the that this is different from the clement wise Squaring of the matrix ( M 2). To do this, follow these steps income che of them (M2) Note a. Read a 2x2 matrix from the user and store it in M. Make sure you let the user know what to input b. Print the dimensions of the matrix,...

  • 4-6 on matlab 4. Write a program in a script file that determines the real roots...

    4-6 on matlab 4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...

  • It is required to write a Matrix Calculator Program using C Programming Language that could only...

    It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each matrix row-wise. Your program...

  • Need help please! Question 1: you must use if /else statement to receive credit for this...

    Need help please! Question 1: you must use if /else statement to receive credit for this question Write a MATLAB script to prompt the user to enter the value of t and use if /else statement to calculate f(t): 0. ift 0.5 f)2t2, if 0.5<t<1 4t. for all other t Test your code with different values of t. Question2: you must use switch/case to receive credit for this question Create a script to prompt the user to enter TWO numbers....

  • Problem 3 (20 pts) It is required to write a Matrix Calculator Program using C Programming...

    Problem 3 (20 pts) It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each...

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • Matlab Question 2. For this problem you have to create a program that defines two vectors...

    Matlab Question 2. For this problem you have to create a program that defines two vectors of numbers: A and B and uses a for-loop to combine the values of A and B. Note that different parts of the question below specify different orders for combining the elements. To start this exercise start a MATLAB script called q2.m and put, at the top, the vector definition: B [11:20] Question 2a: Problem definition Copy the file q2.m to q2a.m. For this...

  • In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use...

    In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use meaningful variable names for each variable; do not use the default variable ans to store your results. For this project, suppress your output with semi-colons (;). Each problem should be in a separate cell, using the cell mode feature of MATLAB. Problem 4 Video games are rather complicated to program, not least of which because of the graphics work that needs to be completed...

  • Write a program which gets user choice for addition, subtraction, multiplication and division with characters ’+’,...

    Write a program which gets user choice for addition, subtraction, multiplication and division with characters ’+’, ’-’, ’*’, and ’/’ respectively. This program should keep asking for two numbers and a choice to perform such operations inside a loop which can be only stopped by entering ’q’. I've been working out of code blocks and now I'm not sure how to go about this iew Search Project Build Debug Fortran wwSmith Tools Tools+ Plugins DoxyBlocks Settings Help maino: int -NM...

  • I only need help on doing number 4 LON-CAPA COurse ConSSOE-First ear-SprirASSGT9 (1)pd softEdge elackboard Conter...

    I only need help on doing number 4 LON-CAPA COurse ConSSOE-First ear-SprirASSGT9 (1)pd softEdge elackboard Conter 4d Metro Boomin No mpstate/Downloads/ASSGT9%20(1) pdf Users/april/AppData/Local/Pac Your task: Design, code, and debug a MATLAB script that: (1) Asks the user (use a nenu) what kind of function (m-file or anonymous function) will be used. If an m-file, have the user enter the filename; if an anonymous function, have the user enter the function (hint: use MATLAB's eval function in your script to appropriately...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT