フィルターのクリア

How do i define the recursive function?

278 ビュー (過去 30 日間)
Yeap Jia Wei
Yeap Jia Wei 2015 年 5 月 12 日
コメント済み: Walter Roberson 2022 年 4 月 13 日
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 件のコメント
Joshua Iascau
Joshua Iascau 2022 年 4 月 13 日
Sorry I use Yahoo
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 Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by