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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:37:48+00:00 2026-05-28T02:37:48+00:00

I know Matlab has built-in functions for determining the associated Legendre functions. I want

  • 0

I know Matlab has built-in functions for determining the associated Legendre functions. I want to compute the Legendre polynomials which are a particular case of those ones. I have written my own code for this task and I have compared with the Matlab built-in functions. Here is the comparison code:

function op
t1 = zeros(1,100);
t2 = zeros(1,100);
P1 = zeros(1,10);
for m = 1:100
tic;
% It is neccessary a for loop for the first ten terms (m =1,...,10) of 
% Legendre polynomial with legendre matlab built-in function
for i = 1:10
    A = legendre(i,0);% legendre function determines the associated 
    % Legendre functions
    P1(i) = A(1,1);% Legendre polynomials are the first row of A
end
t1(m) = toc;
tic;
% My own function determines the first ten terms at a time
P2 = legendrep2(0,10);
t2(m) = toc;
end
% Mean time using the Matlab built-in legendre functions
t1_mean = mean(t1),
% Mean time using my own custom legendre polynomial function
t2_mean = mean(t2),

function [Pl] = legendrep2(gamma,fin_suma)
Pl = zeros(1,fin_suma);
Pl(1) = gamma;
Pl(2) = 0.5*(3*gamma*Pl(1)-1);
    for j =3:fin_suma;
        Pl(j) = ((2*j-1)*gamma*Pl(j-1)-(j-1)*Pl(j-2))/j;
    end
end
end

These are my results:

t1_mean =
     0.001621042906210
t2_mean =
      7.536710452587590e-006

So, I would like to know if there is any possibility to improve my code (legendrep2 function) still more.

  • 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-05-28T02:37:49+00:00Added an answer on May 28, 2026 at 2:37 am

    Try the Matlab profiler to find out where the bottleneck is:

    Menu -> Desktop -> Profiler

    This will help you focus.

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

Sidebar

Related Questions

I am using MATLAB R2008a and I want to know what source control has
I know Matlab has a function called cylinder to create the points for a
I'm completely new to MATLAB and I want to know what my options are
I'm implementing PCA using eigenvalue decomposition for sparse data. I know matlab has PCA
i want to plot a 3d graph using surf in matlab. i know how
I know that Matlab allows for you to format the graph after its created
My knowledge of matlab is merely on a need to know basis, so this
I would like to know how I can record a video in MATLAB with
I have some Matlab code and a GUI for it and I want to
I know I can create a 3D surface plot in MATLAB by doing: x

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.