Question

2. Legrendre polynomials are sometimes used in applied mathematics. The first 3 Legrendre polynomials are: , Pi(x)-x, P2(x) = 2 For i> 2 subsequent Legrendre polynomials may be generated by the following formula: Pi = (2 * i-1) * x *P1-(i-1)*P-2 Let x = 0.66. Using VBA, calculate P2 through P10 using a For loop. Begin with and turn in a owchart with your solution.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

VBA Code:

Public Function Legendre(n As Integer, x As Double) As Double
'Computes the nth Legendre polynomial given x

Dim Pn As Double, Pn_1 As Double, Pn_2 As Double
Dim j As Integer
If n < 0 Then
MsgBox "n must be >= 0. Error"
Legendre = 0
Exit Function
End If
'P0 is 1 and P1 is x.
If n = 0 Then
Pn = 1
ElseIf n = 1 Then
Pn = x
Else 'n >= 2
Pn_1 = 1
Pn = x
For j = 2 To n
Pn_2 = Pn_1
Pn_1 = Pn
Pn = (((2 * j - 1) * x * Pn_1) - ((j - 1) * Pn_2)) / j
Next j
End If
Legendre = Pn
End Function

Flowchart:

Function execution results:

Description:

As stated in the problem using values from P0(X), P1(X) and formula for  Legendre equation used a for loop to implement the value assignment for Pn(X) and displayed the results.

Add a comment
Know the answer?
Add Answer to:
2. Legrendre polynomials are sometimes used in applied mathematics. The first 3 Legrendre polynomials are: ,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT