Question

In: Computer Science

Create a function to output a one dimensional double array Mwith n elements where the...

Create a function to output a one dimensional double array M with n elements where the first three elements are 1 and each subsequent element is the sum of previous three elements before it. Name the function myArray. Write the function in the correct format to be used to create a Matlab function. Call the function in correct format to output the array with 7 elements.

Solutions

Expert Solution

code :

output :

raw_code :

function M = subsequent(n)
  
M = double([1,1,1,]); %assigning first three elements to 1
for i = n-3:n
  
M(i) = M(i-1)+M(i-2)+M(i-3); %adding previous three numbers
  
end
  
end

 


Related Solutions

Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the...
Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the number of rows and columns, respectively, define a function named sqabsmax that accepts array A as an argument (i.e. input parameter) and returns the square of the maximum absolute value element in A. Use the const qualifier if appropriate. Only show the function definition. Do not write an entire program with a main function. Just write the definition for function sqabsmax. in C
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
Create a function output() in C that takes the pointer to the array and its size...
Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (function prototype : void output(int *arrayPtr, int size);
One dimensional dynamic array Write a function that returns the number of integers in an input...
One dimensional dynamic array Write a function that returns the number of integers in an input file stream with the following interface: int findNumber(ifstream &x); Then, use this number to dynamically allocate an integer array. Write another function that reads each number in an input file stream and assign the value to the corresponding array element with the following interface: void assignNumber(ifstream &x, int y[ ]); In your main( ), first open “in.dat” as an input file. Next, apply findNumber(...
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
In MATLAB Write a function to create an array of N numbers with a normal distribution....
In MATLAB Write a function to create an array of N numbers with a normal distribution. Call that from a script to create 1000 numbers, with a mean of 50 and a sigma of 10.
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
Im trying to create a function in C where it takes an array and size and...
Im trying to create a function in C where it takes an array and size and returns the largest absolute value in the array (either negative or positive) using only stdio.h. Any help would be greatly appreciated! Ex: if the array is { -2.5, -10.1, 5.2, 7.0}, it should return -10.1 Ex: if the array is {5.1, 2.3, 4.9, 1.0}, it should return 5.1. double getMaxAbsolute(double array[], int size) {     double max = array[0];    double abs[size];    for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT