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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:04:17+00:00 2026-06-15T14:04:17+00:00

I’m trying to span values of a certain multivariable function f(nu,delta,Omega,kappa,Gamma) . The code

  • 0

I’m trying to span values of a certain multivariable function f(nu,delta,Omega,kappa,Gamma). The code is as follows:

% PREALLOCATE RESULT MATRIX

N = 10;
d = 0.1;

M = zeros(4*N/d+(2*N+1)/d,6);

% SET UP LOOP INDICES

i=1;
increm=1;

% LOOP OVER MULTIPLE VARIABLE

for nu=d:d:N
    for delta=-N:d:N
        for Omega=d:d:N
            for kappa=d:d:N
                tic
                for Gamma=d:d:N

                % CALCULATE THE FUNCTION 

                mss = ((Gamma+kappa).*((Gamma+kappa).^2+4.*(delta+(-1).*nu).^2).^(-1)+( ...
                  -1).*(Gamma+kappa).*((Gamma+kappa).^2+4.*(delta+nu).^2).^(-1)+( ...
                  kappa.^2+4.*(delta+(-1).*nu).^2).^(-1).*(((2.*Gamma+kappa).^2+4.*( ...
                  delta+(-1).*nu).^2).*(kappa.*(Gamma+kappa).*(2.*Gamma+kappa)+4.*(( ...
                  -1).*Gamma+kappa).*(delta+(-1).*nu).^2)+4.*(kappa.*(2.*Gamma+ ...
                  kappa).^2+4.*(4.*Gamma+kappa).*(delta+(-1).*nu).^2).*Omega.^2).*( ...
                  16.*(delta+(-1).*nu).^4+4.*(delta+(-1).*nu).^2.*((Gamma+kappa).^2+ ...
                  (2.*Gamma+kappa).^2+(-8).*Omega.^2)+((Gamma+kappa).*(2.*Gamma+ ...
                  kappa)+4.*Omega.^2).^2).^(-1)+(-1).*(kappa.^2+4.*(delta+nu).^2).^( ...
                  -1).*(((2.*Gamma+kappa).^2+4.*(delta+nu).^2).*(kappa.*(Gamma+ ...
                  kappa).*(2.*Gamma+kappa)+4.*((-1).*Gamma+kappa).*(delta+nu).^2)+ ...
                  4.*(kappa.*(2.*Gamma+kappa).^2+4.*(4.*Gamma+kappa).*(delta+nu).^2) ...
                  .*Omega.^2).*(16.*(delta+nu).^4+4.*(delta+nu).^2.*((Gamma+kappa) ...
                  .^2+(2.*Gamma+kappa).^2+(-8).*Omega.^2)+((Gamma+kappa).*(2.*Gamma+ ...
                  kappa)+4.*Omega.^2).^2).^(-1)).^(-1).*((Gamma+kappa).*((Gamma+ ...
                  kappa).^2+4.*(delta+nu).^2).^(-1)+(kappa.^2+4.*(delta+nu).^2).^( ...
                  -1).*(((2.*Gamma+kappa).^2+4.*(delta+nu).^2).*(kappa.*(Gamma+ ...
                  kappa).*(2.*Gamma+kappa)+4.*((-1).*Gamma+kappa).*(delta+nu).^2)+ ...
                  4.*(kappa.*(2.*Gamma+kappa).^2+4.*(4.*Gamma+kappa).*(delta+nu).^2) ...
                  .*Omega.^2).*(16.*(delta+nu).^4+4.*(delta+nu).^2.*((Gamma+kappa) ...
                  .^2+(2.*Gamma+kappa).^2+(-8).*Omega.^2)+((Gamma+kappa).*(2.*Gamma+ ...
                  kappa)+4.*Omega.^2).^2).^(-1));

                % STORE THE RESULT

                M(i,:) = [mss nu delta Omega kappa Gamma];

                i = i+increm;

                end
            end
            toc
        end
    end
end

save M

However the preallocation does not help that each iteration takes longer time. When I run the code and interrupt it prematurely, the iterations take

Elapsed time is 0.003354 seconds.
Elapsed time is 0.006374 seconds.
Elapsed time is 0.009043 seconds.
Elapsed time is 0.012092 seconds.
Elapsed time is 0.015287 seconds.
Elapsed time is 0.019239 seconds.
Elapsed time is 0.023898 seconds.
Elapsed time is 0.035345 seconds.
Elapsed time is 0.046675 seconds.
Elapsed time is 0.056000 seconds.
Elapsed time is 0.066323 seconds.
Elapsed time is 0.072178 seconds.
Elapsed time is 0.075174 seconds.
Elapsed time is 0.081095 seconds.
Elapsed time is 0.095016 seconds.
Elapsed time is 0.095214 seconds.
Elapsed time is 0.100089 seconds.
Elapsed time is 0.104286 seconds.
Elapsed time is 0.109454 seconds.
Elapsed time is 0.115368 seconds.
Elapsed time is 0.124278 seconds.
Elapsed time is 0.131521 seconds.
Elapsed time is 0.135023 seconds.
Elapsed time is 0.137370 seconds.
Elapsed time is 0.145331 seconds.
Elapsed time is 0.163449 seconds.
Elapsed time is 0.162654 seconds.
Elapsed time is 0.159628 seconds.
Elapsed time is 0.166585 seconds.

I don’t see how the change of variables itself could cause this, because the only vary by amount d, which shouldn’t make it much harder to calculate the new value of mss than in the previous interation.

  • 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-15T14:04:17+00:00Added an answer on June 15, 2026 at 2:04 pm

    You aren’t pre-allocating a big enough array!

    If you do the following nested loop

    for ii=1:3
       for jj = 1:4
           doSomething()
       end
    end
    

    doSomething is executed 3*4=12 times. With your allocation scheme, you would be allocating 3+4=7 times.

    In other words, change your preallocation to

    M = zeros((N/d)^4*(2*N+1)/d,6);
    

    and all will be fine.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words

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.