Azzera filtri
Azzera filtri

How do i define the recursive function?

278 visualizzazioni (ultimi 30 giorni)
Yeap Jia Wei
Yeap Jia Wei il 12 Mag 2015
Commentato: Walter Roberson il 13 Apr 2022
The first three Legendre polynomials are P0(x) = 1, P1(x) = x, and P2(x) = (3x2−1)/2. There is a general recurrence formula for Legendre polynomials, by which they are defined recursively:
(n+1)Pn+1(x)−(2n+1)xPn(x)+nPn−1(x)=0.
Define a recursive function p(n,x) to generate Legendre polynomials, given the form of P0 and P1. Use your function to compute p(2,x) for a few values of x, and compare your results with those using the analytic form of P2(x) given above.

Risposte (3)

Celeste Dodge
Celeste Dodge il 17 Set 2019
wow poeple are mean
  4 Commenti
irvin rynning
irvin rynning il 13 Dic 2021
i get the sense i'm on stackoverflow, not a professional forum, with responses such as yours
Walter Roberson
Walter Roberson il 15 Dic 2021
The time and attention of the volunteers (unpaid!) is a scarce resource. Over 140 new questions are asked every day; in the March time-frame it peaks over 250 new questions every day. Some of the questions take a few seconds to answer; some of them take a couple of days of effort to answer. It is typical that any given question takes at least two days to get through, back and forths with the person who asked the question. So any given volunteer is pretty much having to pick through over 275 active questions every day.
The volunteers have to decide: do they give detailed attention to the people who are actually trying to solve MATLAB problems and are likely to benefit from mentoring? Or do they give detailed attention to the people who copy and paste homework problems and do not even attempt to solve the problem? Because I can assure you, the volunteers do not have time to do both. I am already working on over 50 different Questions every day.

Accedi per commentare.


Walter Roberson
Walter Roberson il 12 Mag 2015
Modificato: Walter Roberson il 12 Mar 2021
This is not a MATLAB question. The relevant MATLAB question is "How do I create recursive functions", and the answer to that is that you just have the function call itself. The only tricks are to make sure you call with different arguments or else you infinite loop; and to make sure you have an ending condition.
Example:
function r = myfactorial(n)
if n <= 0
r = 1;
else
r = n * myfactorial(n-1);
end
end
Everything else about your question is "Do my homework for me!"
  2 Commenti
rajesh mishra
rajesh mishra il 29 Ago 2021
No offence but your answer is completly useless, what the person is asking is that how can we create array of function and evalulate that function for particular value of x and n ,
Walter Roberson
Walter Roberson il 15 Dic 2021
You are mistaken. The task is specifically to create a recursive function. It says so in the problem, "Define a recursive function p(n,x) to generate Legendre polynomials, given the form of P0 and P1. " Not an array of functions.
There are optimizations potentially available if you store functions... but in practice not really. The optimizations more come in if you can build up formulas and store them, such as is possible using the Symbolic Toolbox. Working out the formulas as pure text in order to generate functions and store them, gets a bit nasty. (Hmmm, I wonder if it can be phrased in terms of convolutions and filters ?)

Accedi per commentare.


Torsten
Torsten il 12 Mag 2015
  2 Commenti
Walter Roberson
Walter Roberson il 13 Apr 2022
Then we recommend that you learn how to use the Google search engine. The Advanced Search makes it much easier to locate specific content, and a number of features of the advanced search can be called up from the command line if you know the right codes.
For example,
recursive function site:mathworks.com
would restrict the search to mathworks.com

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by