{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

legendrep

legendrep - function p=legendrep(m,x function which...

This preview shows pages 1–2. Sign up to view the full content.

function p=legendrep(m,x) % function which construct Legendre polynomial Pm(x) % where M is the degree of polynomial and X is the variable. % Result - P is the char string that should be evaluated EVAL(P) % Example: % P=legendrep(2,'cos(theta)') will produce % P='(3*cos(theta).^2 -1)/2' which then can be evaluated as % theta=0.3; P=legendrep(2,'cos(theta)'); Lp=eval(P); produce % Lp = 0.8690 % For Matlab R14 the following example can be used: % x=-5:.1:5; p=legendrep(5,'x .*cos(x)'); xp = eval(p); % figure; plot(x, xp, 'r.-'); grid % % References: % Gradshteyn, Ryzhik "Table of Integrals Series and Products", 6th ed., p.973 % %__________________________________________________ % Sergei Koptenko, Resonant Medical Inc., Toronto % %______________March/30/2004_______________________ % switch m case 0 p='1'; return case 1 p=x; return case 2 p=['(3*' x '.^2 -1)/2']; return case 3 p=['(5*' x '.^3 - 3 *' x ')/2']; return case 4 p=['(35 *' x '.^4 - 30 * ' x '.^2 + 3)/8']; return case 5 p=['( 63 * ' x '.^5 - 70 * ' x '.^3 + 15 *' x ' )/8']; return case 6 p=['(231 *' x '.^6 - 315 * ' x '.^4 + 105 * ' x '.^2 -5)/16'];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

legendrep - function p=legendrep(m,x function which...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online