1)
a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code.
b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19


%%Matlab code integral
clear all
close all
%loop for finding integration using A
fprintf('Integration using formula A\n')
for i=1:19
val=int_fun(i);
fprintf('\tFor n=%d the integral value is
%f\n',i,val)
end
%loop for finding integration using B
in_val(1)=1-1/exp(1);
fprintf('Integration using formula B\n')
for i=1:19
val=i*in_val(i)-(1/exp(1));
in_val(i+1)=val;
fprintf('\tFor n=%d the integral value is
%f\n',i,val)
end
%function for integration
function val=int_fun(n)
fun=@(x)
x.^n.*exp(-x);
val=integral(fun,0,1);
end
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...
In matlab, there is a function "size" that accepts an array as a
parameter (or input argument) and returns the dimensions of that
array as another single-dimension array.
For example, if the array were 2 x 2, it
would return [2 2]. Assume that input1 is a 1 or 2-dimensional
array. Use the size function to obtain the dimensions and save the
output into the return argument of this function "output1"
1Do not modify the line below 2-unction...
*** write in matlab *** use for loops
largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir). You must use a for loop to solve this problem. Do not use functions factor), primes(), and divisors() . Do not use while loops Do not use vectorized code. alargestfactor 105) 35
largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir)....
C++ //Write prototype for function factorial that accepts an int num and returns an int /* WITH LOOP OF YOUR CHOICE: Write code for function factorial that accepts an int num and returns the num's factorial factorial(5); 1*2*3*4*5 returns 120 DON'T FORGET TO WRITE TEST CASE. */ //write includes statements //write using statements for cin and cout /* Use a do while loop to prompt the user for a number, call the factorial function, and display the number's factorial. Also,...
C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa parameter */ //get_letter_grade.cpp /* Write function code for gpa_to_letter_grade that returns a string and accepts a double gpa parameter YOU MUST USE A SWITCH STATEMENT Given a double 3.5 returns the string A TIP: You'll have to convert the double to an int using multiplication Table 3.5 to 4 returns an A 3.0 to 3.49 returns a B 1.7 to 2.99 returns a C...
Write a method named factorial that accepts an integer n as a parameter and returns the factorial of n, or n!. A factorial of an integer is defined as the product of all integers from 1 through that integer inclusive. For example, the call of factorial(4) should return 1 2 3 4, or 24. The factorial of 0 and 1 are defined to be 1. You may assume that the value passed is non-negative and that its factorial can fit...
C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....
Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example: multiply([ 1, 2, 3], 3) → 6 multiply([1, 1, 4 ,2], 4) → 8 multiply([7, 0, 0, 7, 0, 7],...
MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB
Using C++ write a function AllSame(a,n) that returns 1 if all components of the positive integer array a[0 .. n-1] have the same sums of digits; otherwise it returns 0. E.g. the array a [ ] = {17, 242, 62, 35, 431, 8} has the same sums of digits and AllSame(a, 5) returns 1.