Hi Rajveer
To adapt this code for solving the Legendre differential equation, we can remove the user input for the general equation and hard-code the specifics of the Legendre differential equation. Here is the code for your reference:
clc
clear all
syms x y(x) n
% Legendre Differential Equation
LDE = (1 - x^2)*diff(y, x, 2) - 2*x*diff(y, x) + n*(n+1)*y == 0;
% Solve the Legendre Differential Equation
ySol = dsolve(LDE);
% Display the solution
disp(ySol)
Above code defines the Legendre differential equation and then uses dsolve function to find the solution. The variable n is kept as a symbolic variable, which means the solution will be in terms of n. You may specify a particular value of n if you are interested in a specific solution corresponding to that value.
Hope it helps!