0% found this document useful (0 votes)
24 views6 pages

LAB4

Uploaded by

kate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

LAB4

Uploaded by

kate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

BATAAN PENINSULA STATE UNIVERSITY

COLLEGE OF ENGINEERING AND ARCHITECTURE


DEPARTMENT OF ELECTRONICS ENGINEERING

ECEM 0313
Laboratory Activity 4
POWER SERIES AND
FROBENIUS METHOD

December 12, 2022

SADJE, KATE NICHOLLE A.


BSECE III - B

Score

ENGR. KRISTINE P. ORTEGA


Code
clc, clear, close all
maintopic = 0;
topic = [1 2 3];
while maintopic == 0;
clc;
disp('-------------Welcome to Power Series and Frobenius Method Solver----
---------');
inp1 = input('What method would you like to try?\n1 - 1st Order Power
Series\n2 - 2nd Order Power Series\n3 - Frobenius Method\nType in the number of
the type of ODE you would like to solve.\n');
if(any(topic(:)== inp1))
maintopic = inp1;
end
end
if(maintopic == 1)%1st Order Power Series
syms y(x) a0 a1 a2 a3 a4 a5 x
fprintf('Equation: y``+51x+y`-52y==0\n');
fprintf('Sample input: diff(y,x,2)+51*x+diff(y,x)-52*y==0\n')
INP = input ('Type in your ODE: ');
sODE = collect (simplify (INP));
yA = (a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5);
dyA = diff (yA);
PS = subs (sODE, {diff(y,x), y}, {dyA, yA});
sPS = collect (simplify (PS));
Term2 = subs (sPS, x, 0);
T2 = solve (Term2, a2);
Term4 = subs (sPS, {x^5, x^4, x^3, a1, a2, a3}, {0, 0, 0,0, T2, 0});
T4 = solve (Term4, a4);
GEN = subs (yA, {a1, a2, a3, a4, a5}, {0, T2, 0, T4, 0});
EQN = collect (simplify (GEN));
disp ('Power Series Solution is y(x) = ');
disp (EQN);
elseif(maintopic == 2)%2nd Order Power Series
syms y(x) a0 a1 a2 a3 a4 a5 x
fprintf('Equation: y``+51xy`-52y==0\n');
fprintf('Sample input: diff(y,x,2)+51*x*diff(y,x)-52*y==0\n')
INP = input ('Type in your ODE: ');
sODE = collect (simplify (INP));
yA = (a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5);
dyA = diff (yA);
dy2A = diff (dyA);
PS = subs (sODE, {diff(y,x,2), diff(y,x), y}, {dy2A, dyA, yA});
sPS = collect (simplify (PS));
Term2 = subs (sPS, x, 0);
T2 = solve (Term2, a2);
Term3 = subs (sPS, {x^5, x^4, x^3, x^2, a2}, {0, 0, 0, 0, T2});
T3 = solve (Term3, a3);
Term4 = subs (sPS, {x^5, x^4, x^3, a1, a2, a3}, {0, 0, 0, 0, T2, 0});
T4 = solve (Term4, a4);
Term5a = subs (sPS, {x^5, x^4, x^2, a1, a2, a3}, {0, 0, 0, 0, T2, T3});
T5b = subs (Term5a, a1*x, 0);
T5 = solve (T5b, a5);
Gen = subs (yA, {a2, a3, a4, a5}, {T2, T3, T4, T5});
EQN = collect (simplify (Gen));
disp ('Power Series Solution is y(x) = ');
disp (EQN);
elseif(maintopic == 3)%Frobenius Method
syms y(x) a0 a1 a2 a3 a4 a5 x
fprintf('Equation: 1x^2*y``-(4x^3+2)y+1xy`=0\n');
fprintf('Sample input: 1*x^2*diff(y,x,2)-(4*x^3+2)*y+1*x*diff(y,x)==0\n')
ODE = input ('Type in your ODE: ');
lhsODE = ODE;
rhsODE = 0;
ODE2 = lhsODE - rhsODE;
sODE = collect (simplify (ODE2));
rval = x;
yB = x^rval*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5);
dyB = diff (yB);
dy2B = diff (dyB);
FM = subs (sODE, {diff(y,x,2), diff(y,x), y}, {dy2B, dyB, yB});
sFM = collect (simplify (FM));
disp (sFM);
nval = input ('Input the exponent of factored, example 2/3: ');
N = nval*(-1);
sFM2 = collect(simplify (x^N*sFM));
Term1 = subs (sFM2, a0,{0, 0, 0, 0, 0, 0});
T1 = solve (Term1, a1);
Term2 = subs (sFM2, {x^6, x^5, x^4, x^3, x^2, a1}, {0, 0, 0, 0, 0, T1});
T2 = solve (Term2, a2);
Term3 = subs (sFM2, {x^6, x^5, x^4, x^3, a0, a1, a2}, {0, 0, 0, 0, 0, T1,
0});
T3 = solve (Term3, a3);
Term4a = subs (sFM2, {x^6, x^5, x^4, x^2, a0, a1, a2},{0, 0, 0, 0, 0, T1,
T2});
Term4b = subs (Term4a, a0*x, 0);
T4 = solve (Term4b, a4);
Term5 = subs (sFM2, {x^6, x^5, x^3, x^2, a0, a1, a2, a3},{0, 0, 0, 0, 0,
T1, 0, T3});
T5 = solve (Term5, a5);
Gen = subs (yB, {a1, a2, a3, a4, a5}, {T1, T2, T3, T4,T5});
EQN = collect (simplify (Gen));
disp ('The Frobeneus Solution is y(x) = ');
disp (EQN);

else
disp('Incorrect input, please try to re-running the program')
end
Start Up

Five Examples

You might also like