” MATH 2109程序 写作、 辅导Java,c++School of SciencesMATH 2109 Mathematical Computing Week 6 Hand in Lab Class Due 5 : 00pm Friday 23rd April 2021.1. Write a function in an m-file for y = cos5(x) sin3(x) + 2 that will accept a Row vector of xvalues as input and output a row vector of y values. Now generate a row vector of x values inthe interval [0, 7] (use 100 points) and input this into your function to find the correspondingy values. Plot the function using the plot() command. Also by looking up the xlabel()and ylabel() functions label the x and y axes.2. A sequence is given by a5 = 2, a6 = 4, and a7 = 1, and the recurrence relationan = 5 an1 3 an2 + 6 an3an2when n 8.Write a function in an m-file that has n as its only input, where n 5, and returns the valuean. Put in a check that n 5 and exit with a printed error if this is not the case, assigningan the value NaN.Call your function in a main program, so that it prints, using fprintf, a table of values forn and f(n), for n = 5, 6, . . . 13. Your table should have headers.3. The symbolic toolbox allows us to integrate symbolic expressions using the following commands(as an example):f = @(x) cos(x). 5.*sin(x). 3syms x ;int(f(x),x)ans =(cos(x) 5*(5*cos(x) 2 – 7))/35Write a function call IntFunct in an m-file that takes as input a function of one variableand values of a and b for x. As outputs it returns the value of the definite integral over theinterval [a, b] and (only if asked for) additionally a symbolic expression for its derivative. Alsoinclude a check that not more than 2 outputs are requested and if they are, return a printederror message (of your making) and cease execution before Matlab complains. Test this bycalculating the integral of y = cos5(x) sin3(x) over [0, 2]. You need to pass the function fand the values a = 0 and b = 2 as Parameters when you call the function from the commandwindow.[Hint: Use double(subs(Sym_Expression, x, a)) to get a number after substituting. ]4. The intersection of a circular cylinder of unit radius, oriented around the xn axis, and thesphere centred at the point e1 = (1, 0, . . . , 0) correspond to the points (x1, x2, . . . , xn) (inn-dimensions) that satisfy the equations:Write a function area_approx = Monte_Carlo_Test(n,N) that inputs the dimension nand the number of random samples N in the following Monte-Carlo estimation of the volume1of the intersection. Generate N uniformly distributed random samples in the following ndimensional box that contains the region defined in (1):and count the number k, of the N, Events that land inside the region defined in (1). Include this function as a sub-functions (place it atthe end of your work) and call it to print a table of the areas associated with the dimensionsn = 3, 4, 5, 6 using N = 106.[Hint: Watch the week 5 Wednesday Lectorial Collaborate Ultra recording.]NOTE : Note that M-File functions MUST NOT contain any fprintf() or disp() commands,or echo print any values inside the function (other than for error messages). The Function MUSTreturn a value or values, NOT just print them with a disp() command.You MUST include listings of Your functions in your published output as follows. If your functionis contained in the M-file with name myfunction.m, just include the linetype myfunction.mat the point in your code where you want the listing of the function to appear.请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。