0% found this document useful (0 votes)
12 views9 pages

Lab Rep 1

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)
12 views9 pages

Lab Rep 1

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/ 9

BATAAN PENINSULA STATE UNIVERSITY

COLLEGE OF ENGINEERING AND ARCHITECTURE


DEPARTMENT OF ELECTRONICS ENGINEERING

ECEM 0313
Laboratory Report 1

January 27, 2023

SADJE, KATE NICHOLLE A.


BSECE III - B

Score

ENGR. KRISTINE P. ORTEGA


SOURCE CODE:
clc, clear
fprintf ('Choose a number from the options below:\n\n') fprintf('1-
Laplace/Inverse Laplace Transform\n2- Power Series\n3- Frobenius
Method\n4- Direction Field\n5- Euler’sMethod\n6- Modified Euler’s
Method\n7- Taylor’s Method\n') while true
method = input(''); if
isequal(method,1)
syms s t Y
prompt = {'Type the the right hand side function(EX.exp(-t)): ',
'Type the the left hand side function(EX.Y2 + 3*Y1 + 2*Y):',
'Type the initial value problem condition. ' , 'Type the
initial value problem condition. ', };reqn =
(input(prompt{1}));
lap = laplace(reqn, t ,s);con1
= input(prompt{3}); con2 =
input(prompt{4}); Y1 = s*Y-
con1;
Y2 = s*Y1-con2;
leqn = (input(prompt{2})); Sol =
solve(leqn - lap, Y);ilap =
ilaplace(Sol,s,t);
fprintf ('Equation:\n%s = %s\n',leqn,reqn);
fprintf ('Initial Value Condition:\ny(0) = %d\ny(0)=
%d\n',con1,con2)
fprintf ('Laplace Transform:\n%s\n',Sol)
fprintf ('Inverse Laplace Transform:\n%s\n',ilap);d=0;
break;
elseif isequal(method,2)syms
y(t)
eqn = input('Type your Equation(Ex.2*t*diff(y,2) + t*y +diff(y) ==
0:\n');
Sol = dsolve(eqn, 'ExpansionPoint' , 0);disp
('Power Series')
d=1;
break;
elseif isequal(method,3)
syms y(t)
eqn = input('Type your Equation(Ex.2*t*diff(y,2) + t*y +diff(y) ==
0:\n');
Sol = dsolve(eqn, 'ExpansionPoint' , 0 );
disp('Frobenius Method')
d=1;
break;
end
syms y(t)
eqn = diff(y,t)== input('Type your Equation(Ex.-
t*y^3):\n');
gsol = dsolve(eqn); cond=input('Conditions(Ex.y(0)==1):\n');
exact=(dsolve(eqn,cond));
d=2;
if isequal(method,4)
for c=linspace(0.25,10,5)
t=linspace(-3,3,100);
plot(t,subs(exact),'b','LineWidth',1);hold on
grid on
end
[t, y] = meshgrid(-3:0.2:3, -3:0.2:3);
S = input('Type your equation like this(Ex.-t.*y.^3):\n');L = sqrt(1
+ S.^2);
quiver(t, y, 1./L, S./L, 0.5);
set(gca, 'XLim', [-3 3], 'YLim', [-3 3]);
disp('Direction Field')
break;
elseif isequal(method,5)syms y
t
eqn = input('Type your equation again:\n');dy1 =
matlabFunction(eqn);
f1 = matlabFunction(exact);t =
input('t = ');
y1 = input('y = ');
h1 =input('Stepsize.h = ');
h = input('# of iterations.n=');tn1
=t+h*h1 ;
disp('Euler''s')
fprintf(' \n')
fprintf('\tt\t\t Euler\t\t Exact\n'); fprintf(' \n')
fprintf (' %f \t %f \t %f\n ', t, y1, f1(t));
for t1= t : h1 : tn1-h1 y1 =
y1 + dy1(t1, y1)*h1;d1 = t1 +
h1;
fprintf ('%f \t %f \t %f \n ', d1,y1,f1(d1))end
break;
elseif isequal(method,6)syms y
t
eqn = input('Type your equation again:\n', 's');
f=inline(eqn);
f1=matlabFunction(exact);
t=input('t = ');
y=input('Initial Value: y(0) = ');h
=input('Stepsize.h = ');
n = input('# of iterations.n = ');tn
=t+h*n;
disp('Modified Euler''s')
fprintf(' \n')
fprintf('\tt\t\t\t Exact\t\t\tModified Euler\n');
fprintf(' \n')
for i=1:n+1
y1=y+h*(f(t,y)+f(t+h,y+h*f(t,y)))/2; fprintf('
%f\t\t%f\t\t%f\n',t,f1(t),y1);t=t+h;
end
break;
else if isequal(method,7)syms t y
f=input('Type your equation again:\n');f1 =
matlabFunction(exact);
a =input('t = ');
ya =input('y = ');
m=input('# of iterations n = ');h =
input('Stepsize h = ');
b = a+m*h;
dfs(1) = symfun(f, [t y]);for
k=1:3
dfs(k+1) = diff(dfs(k),t)+f*diff(dfs(k),y);end
df = matlabFunction(symfun(dfs,[t y]));T =
zeros(1,m+1);
Y = zeros(1,m+1);
T(1) = a;
Y(1) = ya;
for i=1:m
tj = T(i);
yj = Y(i);
D = df(tj,yj);
Y(i+1) = yj + h*(D(1)+h*(D(2)/2+h*(D(3)/6+h*D(4)/24)));
T(i+1) = a + h*i;end
disp ('Taylor''s Method')
fprintf(' \n')
fprintf('\tt\t\t Taylor\t\t Exact\n'); fprintf(' \n')
for i=1: +1 : m+1
t=T(i);
y=Y(i);
fprintf (' %f \t %f \t %f \n', t,y,f1(t));end
break;
else
disp ('Input number must only be 1 to 7!' )end
end
end
if isequal(d,1) disp
('Equation:')disp
(eqn)
disp ('Solution:')
disp (Sol)
else if isequal(d,2)
fprintf('\nEquation:\n')
disp(eqn) fprintf('IVP\n')
disp(cond)
fprintf('General Solution:\n')
disp(gsol)
fprintf('Exact Solution:\n')
disp(exact)
end
end

You might also like