Question: I need help to write my code in rstudio. I do not need to graph, I only need to return the value of the definite
I need help to write my code in rstudio. I do not need to graph, I only need to return the value of the definite integral. Thank you. Also, here is my beginning:
power.integrator = function(A,P,a,b){ if (length(A)!=length(P)){ cat("The length of the coefficient vector must equal the length of the vector of exponents ") return("NA") } else { } }
Definite Integrals of Power Functions The purpose of this exercise is to write the user-defined MATLAB function powerint.m that calculates the value of the definite integral rb | A1.2.P1 + A24P2 + ... + AnqPn dx and graphs the function f(x) = A12P1 + A24P2 + ... + AniqPn. on the interval (a, b). The plot should be smooth. Your inputs will be the vector of coefficients [A1, A2, ..., An), the vector of exponents [P1, P2, ...,pnl, the lower limit a, and the upper limit b. In that order. You must ensure that your function works when one of the exponents equals -1. Re- member that the antiderivative of r-1 equals In(x). Also, the MATLAB command for In(x) is log(x). Your function should give an error when the length of the coefficient vector is not equal to the length of the vector of exponents. Definite Integrals of Power Functions The purpose of this exercise is to write the user-defined MATLAB function powerint.m that calculates the value of the definite integral rb | A1.2.P1 + A24P2 + ... + AnqPn dx and graphs the function f(x) = A12P1 + A24P2 + ... + AniqPn. on the interval (a, b). The plot should be smooth. Your inputs will be the vector of coefficients [A1, A2, ..., An), the vector of exponents [P1, P2, ...,pnl, the lower limit a, and the upper limit b. In that order. You must ensure that your function works when one of the exponents equals -1. Re- member that the antiderivative of r-1 equals In(x). Also, the MATLAB command for In(x) is log(x). Your function should give an error when the length of the coefficient vector is not equal to the length of the vector of exponents
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
