How I can code this Nonuniform Series?

Hi all,
I have a problem in coding of series below:
from n=0 & P0(x)=1. I used handle function in a for loop but I couldn't to save the handle function at the end of each iteration. I appreciate you if you could help me on this problem.
Thanks

4 comentarios

Kevin Chng
Kevin Chng el 11 de Oct. de 2018
Do you mind post your for loop function with your handle function?
Dimitris Kalogiros
Dimitris Kalogiros el 11 de Oct. de 2018
Editada: Dimitris Kalogiros el 11 de Oct. de 2018
Two questions:
1) What is the definition of Pn(x) ?
2) Do you have "symbolic math toolbox" license ?
Torsten
Torsten el 11 de Oct. de 2018
Do these recursively defined polynomials have a name ?
Then maybe googling this name together with "matlab" will give you hints on how to efficiently calculate them.
mohamad hoseini
mohamad hoseini el 12 de Oct. de 2018
Editada: mohamad hoseini el 12 de Oct. de 2018
This is gram-schmidt orthogonalization or process. I have the symbolic math toolbox on my MATLAB. I'll post my code below despite dear "Dimitris Kalogiros" posted a perfect answer to my question.

Iniciar sesión para comentar.

 Respuesta aceptada

Dimitris Kalogiros
Dimitris Kalogiros el 11 de Oct. de 2018
Editada: Dimitris Kalogiros el 11 de Oct. de 2018
Provided that you can use symbolic math toolbox, I suggest the following:
close all; clc; clearvars;
syms n x Pn(x)
% first N polynomials
N=5;
f{N}=0;
% definition for n=0
Pn(x)=1;
f{1}=Pn(x);
% calculation from n=1 up to n=N
for n=1:N
Pn(x)=x^n;
for k=1:n
Pn(x)=Pn(x)- ( int((x^n)*f{k},x,-1,1) / int(f{k}^2,x,-1,1) )* f{k} ;
end
%store next polynomial
f{n+1}=Pn(x);
end
%display all calculated polynomials
for k=0:N
fprintf(' for n = %d ', k);
disp(f{k+1})
end
If you run it , lets say , to calculate P1(x), P2(x),...,P5(x) , you'll get something like this:
The "tip" here is to use the cell array f{}, in order to store all Pn(x) polynomials.

2 comentarios

Walter Roberson
Walter Roberson el 11 de Oct. de 2018
Editada: Walter Roberson el 11 de Oct. de 2018
Alternatively you could phrase it as P{n+1}(x). Which is to say that you can use a cell array of function handles to solve the coding, without using symbolic toolbox.
This is a situation where I would want to analyze to see whether memoize() is appropriate.
mohamad hoseini
mohamad hoseini el 12 de Oct. de 2018
That works completely right dear Dimitris. I appreciate you for sharing your knowledge on my question. I was not familiar with this toolbox before and I know something valuable now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 10 de Oct. de 2018

Editada:

el 12 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by