-u'(x) - (1+x)u''(x)=(x^2)

rovnice = (-D[(x+1)D[u[x],x],x]==x^2)
riesenie=DSolve[{rovnice,u[0]==1,u'[1]==0},u[x],x]
r[x_]=u[x]/.riesenie[[1]]
grafr = Plot[r[x], {x,0,1}, PlotStyle->RGBColor[1,0,0]]

Teraz ideme riesit v MKP

phi0[x_] =1;
phi1[x_] =x^2-2x;
phi2[x_] =x^3 - 3x;
U2[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x]

rez = -D[(x+1) * D[U2[x],x],x] - x^2//Simplify

Najskor si vyskusame to , co sme robili ako prve, ked nam nevyslo riesenie

b = Apart[rez, x]
(*tato funkcia vytiahla vsetky x pred zatvorku*)

rov1 = (Coefficient[b, x, 0] == 0)
(*tato funkcia vytiahne to, co je v becku pri x na nultu*)
rov2 = (Coefficient[b, x, 1] == 0)
rov3 = (Coefficient[b, x, 2] == 0)
Solve[{rov1, rov2 , rov3}, {c1, c2}]

Vysledok je prazdna mnozina, teda rovnica nema riesenie. Bola to naivna metoda....

Budeme skumat metodu vazenych rezidui

Clear[phi0, phi1, phi2, U2, rez, rov1, rov2, s]
phi0[x_] =1;
phi1[x_] =x^2-2x;
phi2[x_] =x^3 - 3x;
U2[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x];
rez = -D[(x+1) * D[U2[x],x],x] - x^2//Simplify;
rov1 = (Integrate[rez * 1,{x,0,1}]==0)
rov2 = (Integrate[rez * x,{x,0,1}]==0)
s= Solve[{rov1, rov2},{c1,c2}]
nr[x_]=U2[x]/.s[[1]]
grafnr = Plot[nr[x],{x,0,1},PlotStyle->RGBColor[0,0,1]]

Show[grafr, grafnr]

Vyvorit 3 funkcie  ... resp. mohol by som spravit viac funkcii

Clear[phi0, phi1, phi2, rez, rov1, rov2, s, nr, grafnr]
phi0[x_] =1;
phi1[x_] =x^2-2x;
phi2[x_] =x^3 - 3x;
phi3[x_] = x^4 - 4x;
U3[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x] + c3 phi3[x];
rez = -D[(x+1) * D[U3[x],x],x] - x^2//Simplify;
rov1 = (Integrate[rez * 1,{x,0,1}]==0)
rov2 = (Integrate[rez * x,{x,0,1}]==0)
rov3 = (Integrate[rez * x^2,{x,0,1}]==0)
s= Solve[{rov1, rov2, rov3},{c1,c2,c3}]
nr[x_]=U3[x]/.s[[1]]
grafnr = Plot[nr[x],{x,0,1},PlotStyle->RGBColor[0,0,1]]

Show[grafr, grafnr]

Vsetky tri sposoby , teda aj s jednou funkciu

Clear[phi0, phi1, phi2, rez, rov1, rov2, s, nr, grafnr]
phi0[x_] =1;
phi1[x_] =x^2-2x;
phi2[x_] =x^3 - 3x;
phi3[x_] = x^4 - 4x;
U1[x_] = phi0[x] + c1 * phi1[x];
U2[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x];
U3[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x] + c3 phi3[x];

rez1 = -D[(x+1) * D[U1[x],x],x] - x^2//Simplify;
rov11 = (Integrate[rez1 * 1,{x,0,1}]==0);
s1 = Solve[{rov11},{c1}];
nr1[x_]=U1[x]/.s1[[1]];
grafnr1 = Plot[nr1[x],{x,0,1},PlotStyle->RGBColor[1,0,0]];

rez2 = -D[(x+1) * D[U2[x],x],x] - x^2//Simplify;
rov21 = (Integrate[rez2 * 1,{x,0,1}]==0);
rov22 = (Integrate[rez2 * x,{x,0,1}]==0);
rov33 = (Integrate[rez2* x^2,{x,0,1}]==0);
s2= Solve[{rov21, rov22},{c1,c2}];
nr2[x_]=U2[x]/.s2[[1]];
grafnr2 = Plot[nr2[x],{x,0,1},PlotStyle->RGBColor[0,1,0]];

rez3 = -D[(x+1) * D[U3[x],x],x] - x^2//Simplify;
rov31 = (Integrate[rez3 * 1,{x,0,1}]==0);
rov32 = (Integrate[rez3 * x,{x,0,1}]==0);
rov33 = (Integrate[rez3 * x^2,{x,0,1}]==0);
s3= Solve[{rov31, rov32, rov33},{c1,c2,c3}];
nr3[x_]=U3[x]/.s3[[1]];
grafnr3 = Plot[nr3[x],{x,0,1},PlotStyle->RGBColor[0.5,1,0.5]];

Show[grafr, grafnr1 , grafnr2 , grafnr3]

Clear[phi0, phi1]
phi0[x_] =1;
phi1[x_] =x^2-2x;
U11[x_] = phi0[x] + c1 * phi1[x];
U12[x_] = phi0[x] + c1 * phi1[x];
U13[x_] = phi0[x] + c1 * phi1[x];

rez1 = -D[(x+1) * D[U11[x],x],x] - x^2//Simplify;

rov11 = (Integrate[rez1 * 1,{x,0,1}]==0);
rov12 = (Integrate[rez1 * x,{x,0,1}]==0);
rov13 = (Integrate[rez1 * x^2,{x,0,1}]==0);
s11 = Solve[{rov11},{c1}];
s12= Solve[{rov12},{c1}];
s13= Solve[{rov13},{c1}];

nr11[x_]=U11[x]/.s11[[1]];
nr12[x_]=U12[x]/.s12[[1]];
nr13[x_]=U13[x]/.s13[[1]];
grafnr11 = Plot[nr11[x],{x,0,1},PlotStyle->RGBColor[0,1,0]];
grafnr12 = Plot[nr12[x],{x,0,1},PlotStyle->RGBColor[1,1,0]];
grafnr13 = Plot[nr13[x],{x,0,1},PlotStyle->RGBColor[1,0,1]];

Show[ grafnr12,grafnr11,grafnr13 , grafr, PlotRange->All]

Clear[phi0, phi1, phi2, U21 , U22, rez2, rov211,rov212, rov221, rov222]
phi0[x_] =1;
phi1[x_] =x^2-2x;
phi2[x_] =x^3 - 3x;
U21[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x];
U22[x_] = phi0[x] + c1 * phi1[x] + c2* phi2[x];

rez2 = -D[(x+1) * D[U2[x],x],x] - x^2//Simplify;

rov211 = (Integrate[rez2 * 1,{x,0,1}]==0);
rov212 = (Integrate[rez2 * x,{x,0,1}]==0);


rov221 = (Integrate[rez2 * x,{x,0,1}]==0);
rov222 = (Integrate[rez2 * x^2,{x,0,1}]==0);

s21= Solve[{rov211, rov212},{c1,c2}];
s22= Solve[{rov221, rov222},{c1,c2}];

nr21[x_]=U21[x]/.s21[[1]];
nr22[x_]=U22[x]/.s22[[1]];

grafnr21 = Plot[nr21[x],{x,0,1},PlotStyle->RGBColor[0,1,0]];
grafnr22 = Plot[nr22[x],{x,0,1},PlotStyle->RGBColor[0,0,0]];

Show[grafr, grafnr21, grafnr22]