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++ //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
Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and outputs the nth Taylor polynomial of the sine function. Compute the absolute and error for n = 1: 10 at x = 1, obtained by comparing the output of your function to that of Matlab's built in sine function. Type on the Matlab console format long, then compute the previous error. Repeat the operation by typing format short. Comment on the result (quantify the...
Write a function that accepts as input a scalar x and an integer n and computes f(x), where f(x) = 1 + x + ... + x^n. For example, if x = 2 and n = 3, the function should return 1 + 2 + 4 + 8 = 15. Hint: Use point-wise operations and the MATLAB sum function. Your Function 1 1 function yf(x) 3 end Code to call your function Your Function 1 1 function yf(x) 3 end...