How do i define the recursive function?

582 次查看(过去 30 天)
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.

回答(3 个)

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

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2015-5-12
编辑:Walter Roberson 2021-3-12
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 个评论
rajesh mishra
rajesh mishra 2021-8-29
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 2021-12-15
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 ?)

请先登录,再进行评论。


Torsten
Torsten 2015-5-12
  2 个评论
Walter Roberson
Walter Roberson 2022-4-13
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by