Welcome To Home of Information

MATLAB function which take value of n and x as argument and display the sum of the following series

Posted in
No comments
Thursday, July 31, 2014 By Anonymous



Write a MATLAB function which take value of n and x as argument and display the sum of the following series. i.e. sum of the factorial of odd series multiply with x where power of x is square of corresponding number. E.g. if n = 5 and x = 1 then it will print 127.
X1*1! + X9*3! + X25*5! + X49*7! + X81*9! + . . . + Xn2*n!
function QUESTION4()                                %Function Start
    n=input('ENTER THE VALUE OF N = ');           %Input n from user
    x=input('ENTER THE VALUE OF X = ');            %Input x from user
    k=1;
    sum=0;
    while k<=n                                     %Loop k to n
        fact=1;
        for i=n:-1:1
            fact=fact*i;                                         %Calculate Factorial of each n
        end
        k=k*k;
        temp=x^k;
        temp=temp*fact;
        sum=sum+temp;                                              %Calculate the sum of series
        k=k+2;
    end                                                  %END while
    disp('SUM IS: ');
    disp(sum);                                     %Display the sum of series
end                                                      %END of Function


Related posts

0 comments:

About the Author

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat volutpat nibh nec posuere. Donec auctor arcut pretium consequat.

Proudly Powered by Blogger.