How can I implement recurrence relations to find polynomials?

Hello everyone. I need to calculate some polynomials using a recurrence rule. I have the values of the polynomials of order zero and one. These are 1 and x. I also have the rule:
Where is the polynomial of order I and both, and are elements of two different vectors that I have stored in memory, so it won’t be difficult to access them. I also need to find the polynomials of order zero to four
Unfortunately, I don't know how to send this to Matlab to find the values of the different polynomials. I can try to do it by hand, but in the future if i need to calculate higher polynomials I will be in trouble.
I have tried to use a matrix to store the values as a matrix, e.g. the first row would be 0 0 0 1 and the second 0 0 x 0 and so on and a for loop to access said elements and then use the recurrence rule. However, I haven't managed to obtain any results.
Can someone please tell me how this could be done and how could I find said polynomials?
Regards.
Jaime.

 Akzeptierte Antwort

Alan Stevens
Alan Stevens am 28 Jan. 2021
Bearbeitet: Alan Stevens am 28 Jan. 2021
Do you mean something along these lines:
order = 4;
a = [0, 0, 1.3, 1.4, 1.5]; % Obviously, replace with your own values.
b = [0, 3.5, 4.5, 5.5, 6.5]; % The initial zeros are simply placeholders
% they are never used here. For higher order
% polynomials a and b will need to be
% correspondingly bigger.
x = 0:0.1:5;
p = zeros(numel(x),1);
for i = 1:numel(x)
p(i) = RPOLY(x(i), order, a, b);
end
plot(x,p),grid
function P = RPOLY(x, order, a, b)
PR = zeros(order+1,1);
PR(1) = 1;
PR(2) = x;
if order == 0
P = PR(1);
elseif order == 1
P = PR(2);
else
for j = 3:order+1
PR(j) = ((x-a(j))*PR(j-1) - b(j-1)*PR(j-2))/b(j);
end
P = PR(order+1);
end
end

4 Kommentare

Hi. First of all, thanks for your answer, but I am afraid this isn't what I am looking for.
I have thwo polynomials, and and the recurrence rule which allows me to calculate the rest of the polynomials e.g.
I want to find the coefficients of each polynomial; in the case of , the coefficients are 0 for , , and x, but is 1 for the independent term. The same way, in the case of the coefficients are 0 for , , and the independent term, but it is 1 for x. My problem is that I don't know how to calculate the different polynomials of order 2 and higher using an automated method in matlab.
This expression
doesn't match the general expression
which, for P2(x), would include b1 in the numerator and b2 in the denominator, rather than b0 in both.
You are right. I have fixed the error. Thanks.
Still doesn't match! The general expression, if correct, would give
Note the indices on the a and the b's.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by