Borrar filtros
Borrar filtros

How do i define the recursive function?

278 visualizaciones (últimos 30 días)
Yeap Jia Wei
Yeap Jia Wei el 12 de Mayo de 2015
Comentada: Walter Roberson el 13 de Abr. de 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.

Respuestas (3)

Celeste Dodge
Celeste Dodge el 17 de Sept. de 2019
wow poeple are mean
  4 comentarios
irvin rynning
irvin rynning el 13 de Dic. de 2021
i get the sense i'm on stackoverflow, not a professional forum, with responses such as yours
Walter Roberson
Walter Roberson el 15 de Dic. de 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.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 12 de Mayo de 2015
Editada: Walter Roberson el 12 de Mzo. de 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 comentarios
rajesh mishra
rajesh mishra el 29 de Ag. de 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 el 15 de Dic. de 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 ?)

Iniciar sesión para comentar.


Torsten
Torsten el 12 de Mayo de 2015
  2 comentarios
Joshua Iascau
Joshua Iascau el 13 de Abr. de 2022
Sorry I use Yahoo
Walter Roberson
Walter Roberson el 13 de Abr. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by