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 8912187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:08:18+00:00 2026-06-15T04:08:18+00:00

I am implementing the adaptive Simpsons method in Matlab recursively. I wish to store

  • 0

I am implementing the adaptive Simpsons method in Matlab recursively. I wish to store all of the points where function evaluations take place to generate a histogram after integrating. I currently have:

function [S, points] = adsimp(f, a, b, fv, tol, level, points)
...
d = (a+b)*0.25;
e = (a+b)*0.75;
points = [points, d, e];
...

Thus, for every function call, I am increasing the length of points by two. My understanding of Matlab’s function input/output scheme is poor. I’d like to know:

1) When the input and output share a variable name, does this use a single variable, or is a local copy made and then returned?

2) If it is a copy, is there a way to pass points by reference and preallocate sufficient memory?

  • 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-15T04:08:19+00:00Added an answer on June 15, 2026 at 4:08 am

    To answer your first question, see here. Most MATLAB variables are passed by value (matrices, etc.) unless it is a handle object (function handle, axis handle etc.) A local copy of an input variable is made only if that variable is altered in the function. ie.

    function y = doTheFunc1(x)
        x(2) = 17;
        y = x;
    

    a copy must be made. As opposed to:

    function y = doTheFunc2(x)
        y = x(1);
    

    where no copy need be made inside the function. In other words, MATLAB is a “copy on write” language. I am almost certain this is true regardless what your output variable output name is (ie. this holds even if your output and input are both named x).

    To answer your second question, look at the first answer here. Consider using a nested function or a handle object.

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

Sidebar

Related Questions

when implementing a recursive function during development, i will use a counter and exit
When implementing a hash table using a good hash function (one where the probability
Implementing Interface just provide the skeleton of the method. If we know the exact
Implementing a custom VM and I've come to use registers (these will store pointers
Implementing a Linked List, store up to 10 names, ordered in first in First
In implementing an interface it seems the common method in tutorials and literature is
I'm setting up an application using Paypal Adaptive Payments. I'm currently implementing the call
Implementing a datastructure with two function pointers, key_eq and key_hash . When these function
When implementing a language that supports all of these constructs, it seems to me
Implementing org.jscep.server.ScepServlet I need to provide an implementation for the method doEnroll ( List<X509Certificate>

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.