Question

Programming Langauge: MATLAB

Write a function with the header: function Q = myTrigFunction (M) which takes a Matrix M filled with integers and returns a matrix Q such that 0(i,j) = sin (pi/M ( i, j )) + 1 0(i,j) = cos (pi/M ( i, j ) ) -1 if M(i,j) is an odd integer and if M(i,j) is an even integer. You may assume elements of M will be greater than 0. Test Cases: >> A= [3 4; 6 7]; >> R = myTrigFunction(A) 1.8660 0.1340 0.2929 1.4339 >>B=[41 3 5 8 12 16 1 106 9; 2 5 12 3 14 17 33 19 11]; >> S = myTrigFunction (B) 1.0765 1.8660 1.5878 0.0761 0.0341 0.0192 1.0000 0.0004 1.3420 1.0000 1.5878 0.0341 1.8660 0.0251 1.1837 1.0951 1.1646 1.2817

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

MATLAB CODE---

FUNCTION FILE.....

function Q=myTrigFunction(M)

[m,n]=size(M);
Q=ones(m,n);
for i=1:m
for j=1:n
if(mod((M(i,j)),2)==1)
Q(i,j)=sin(pi/M(i,j))+1;
else
Q(i,j)=cos(pi/M(i,j))-1;
end
end
end
fprintf('R=\n');
disp(Q);
end


SCRIPT FILE.....
clc;
clear all;
close all;


A=input('ENTER THE MATRIX A=');

R=myTrigFunction(A);

EDIT Usersdeekhya DocumentsMATLAB Editor- C Command Window New to MATLAB? watch this Video, see Examples or read Getting Star

Find Files Compare ▼ Print ▼ Insert Run Section Go To ▼ en Save Breakpoints Run Run and Advance Run and ndent Find Time MATLA

Add a comment
Know the answer?
Add Answer to:
Programming Langauge: MATLAB Write a function with the header: function Q = myTrigFunction (M) which takes...
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
  • The question is attached in following two photos. Please use Matlab if you exactly know how to do it. Thank you. Linorm.m Create a function Linorm which takes one argument, M a square matrix and...

    The question is attached in following two photos. Please use Matlab if you exactly know how to do it. Thank you. Linorm.m Create a function Linorm which takes one argument, M a square matrix and computes the LI-norm of the matrix. This is a number associated to each square matrix M, denoted lIMll, as follows. For each column of the matrix we add together the absolute values of the entries in that column, and we then take the maximum of...

  • 1. Write a MATLAB function that takes a matrix, a row number and a scalar as...

    1. Write a MATLAB function that takes a matrix, a row number and a scalar as arguments and multiplies each element of the row of the matrix by the scalar returning the updated matrix. 2. Write a MATLAB function that takes a matrix, two row numbers and a scalar as arguments and returns a matrix with a linear combination of the rows. For example, if the rows passed to the function were i and j and the scalar was m,...

  • CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive...

    CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive integers and prints every prime number between (and including) them Sample Input: prime(from: 0, to: 100) Sample Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

  • Use the create_matrix function from the tutorial file, along with a function a (i, j) (which...

    Use the create_matrix function from the tutorial file, along with a function a (i, j) (which you will have to create) to produce the following 17 × 17 matrix. Then find its determinant. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 1 1 1 1 1 1 1 1 1 1 1...

  • Why is my multiplication wrong when i do a matrix of 3 x 5 and 2...

    Why is my multiplication wrong when i do a matrix of 3 x 5 and 2 x 2? code below import java.util.*; public class matrix { public static void main(String[] args) { int m, n, i, j; Random rand = new Random(); Scanner scan = new Scanner(System.in); System.out.print("enter how many rows:"); m = scan.nextInt(); System.out.print("enter how many columns:"); n=scan.nextInt(); int matrix_1[][] = new int[m][n]; //Initialize matrixes int maritx_2[][] = new int[m][n]; int matrix_add[][] = new int[m][n]; int matrix_mul[][] = new...

  • USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and...

    USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...

  • Project in matlab. I have the correct ak value but not the correct ao value. My code is attached ...

    Project in matlab. I have the correct ak value but not the correct ao value. My code is attached below also 2. Determine and plot the magnitude and phase spectrum of the Fourier series coefficients a, that is, plot ja, I as a function of discrete frequencies Jok and La, as a function of discrete frequencies fok 03 025 蓋0.2 0.15 0.1 o o5 ·10-8-6 4610 phase -2 -2 8- t= 0: .01:4; 9- to = 4; 10- fo =1/4;...

  • == Programming Assignment == For this assignment you will write a program that controls a set...

    == Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...

  • 느 - K L M N O Р Q R S B с D E F...

    느 - K L M N O Р Q R S B с D E F G H 4 A sample of households provided the following information about their Per Capita Income. 5 Use Excel to construct a percent frequency distribution table and graph. 6 Provide an appropriate label for each of the horizontal and vertical axes. 7 Make your first class "30,000-34,999" 8 Place the frequency distribution table and histogram within the highlighted box below. 9 Per Capita 10...

  • Consider the Java program below to sort an array A in an ascending order. M, N,...

    Consider the Java program below to sort an array A in an ascending order. M, N, and K are positive integers, and A is an array of N nonnegative integers where 0 < A[i] < M for all i e {0,..., N -1}. In this program, list is a class of an integer list with the following methods. 1st.size(): returns the number of elements in the list lst 1st.get(i): returns the element at the i-th position in the list lst...

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