This is a matlab question : In Problem 1a, you can assume that the user correctl
ID: 3602858 • Letter: T
Question
This is a matlab question :
In Problem 1a, you can assume that the user correctly inputs a
positive integer.
In the sum in problem 1, there is an extra negative sign in front of the
formula. Ignore this when making your function.
In Problem 2a, you are creating the vectors, not prompting the user
Problem 1: In the main script, named scriptl, generate a real number x in the range from- to , and prompt the user to enter a positive integer n. Then, call a function funcS that will evaluate the sum of the n terms of the series shown below, (a) In the main script, print the value for S(x,n) in the scientific (e) format by using 3 decimal places. (b) Plot y using dotted black line, y-a- r3/3! using dashed black line, and y-sin(x) using red line in the same figure window. Let x E |-, | with 100 points inbetween. Label the axes as x and y. Make the legend by using: 1 term approx., 2 terms approx., sin(x) 3 2 S(x, n) = x-31 + (-1)" Hint: Use the dot operator, as applied to appropriate arrays, and recall that the factorial) function can be applied to an integer or an array of integers.Explanation / Answer
#include<stdio.h>
#include<math.h>
int fact of(int x)
{
if(x>1)
{
return x*fact(x-1)
}else
{ return 1;
}
}
int main() {
int x.i=1,sign=1;
float result,scanf("%d",x);
while(abs pow(x,i)/fact(i)>100){
result +=sign*(pow(x,i)/fact(i));
i+2;sign=sign* -1;
}
printf("result=%f/n",result);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.