Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:00:54+00:00 2026-06-03T09:00:54+00:00

I am learning MatLab on my own, and I have this assignment in my

  • 0

I am learning MatLab on my own, and I have this assignment in my book which I don’t quite understand. Basically I am writing a function that will calculate sine through the use of Taylor series. My code is as follows so far:

    function y = sine_series(x,n);
    %SINE_SERIES: computes sin(x) from series expansion
    % x may be entered as a vector to allow for multiple calculations simultaneously
    if n <= 0
        error('Input must be positive')
    end
    j = length(x);
    k = [1:n];
    y = ones(j,1);
    for i = 1:j
    y(i) = sum((-1).^(k-1).*(x(i).^(2*k -1))./(factorial(2*k-1)));
    end

The book is now asking me to include an optional output err which will calculate the difference between sin(x) and y. The book hints that I may use nargout to accomplish this, but there are no examples in the book on how to use this, and reading the MatLab help on the subject did not make my any wiser.

If anyone can please help me understand this, I would really appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:00:55+00:00Added an answer on June 3, 2026 at 9:00 am

    The call to nargout checks for the number of output arguments a function is called with. Depending on the size of nargout you can assign entries to the output argument varargout. For your code this would look like:

    function [y varargout]= sine_series(x,n);
    %SINE_SERIES: computes sin(x) from series expansion
    % x may be entered as a vector to allow for multiple calculations simultaneously
    if n <= 0
        error('Input must be positive')
    end
    j = length(x);
    k = [1:n];
    y = ones(j,1);
    for i = 1:j
    y(i) = sum((-1).^(k-1).*(x(i).^(2*k -1))./(factorial(2*k-1)));
    end
    if nargout ==2  
        varargout{1} = sin(x)'-y;  
    end
    

    Compare the output of

    [y] = sine_series(rand(1,10),3)
    

    and

    [y err] = sine_series(rand(1,10),3)
    

    to see the difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Matlab and I see a line that I don't understand: A=[x; y']
Learning some VBA. So far, I've constructed this piece of code which should allow
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I have just started learning MATLAB and have difficulties to import csv files to
I have learned a Machine Learning course using Matlab as a prototyping tool. Since
I've started learning about image processing in Matlab and I have a small problem.
I'm now learning a bit of MATLAB and I have two versions of it.
What is the problem in this program. I am learning Matlab (self teaching). I
I am writing some Machine Learning code in MATLAB, and I am representing a
I have recently started learning MatLab, and wrote the following script today as part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.