Documentos de Académico
Documentos de Profesional
Documentos de Cultura
= 2
1
Matlab code for above integral (Lecture 19)
clear all
close all
clc
%interval
x_int = 1:5;
y = x_int.^2; % given function
%using trapz function
trapz_int = trapz(y);
fprintf('the value of functionis %3.4f\n',trapz_int)
Assignment 5 Codes
Q.4
clear all
close all
clc
%given limits
x=linspace(-1,1);
%function
f= 1\sqrt(1-x.^2);
%using trapeziod rule
result= trapz(x,f)
Q.5
clear all
close all
clc
%given limits
x=linspace(1,3);
y = linspace(0,3);
z=linspace(0,1);
%function Given
f = x.^2+y.^2+z.^2;
% By appliyingtrapezoidal rule
Result = trapz(x,f.*trapz(y,f).*trapz(z,f))
Q.6
clear all
close all
clc
%given limits
x=linspace(0,1);
y = linspace(0,1);
%function Given
f=(x.^2-10.*x.*y-y.^2).^4;
%by using trapeziod rule
Result=trapz(x,f.*trapz(y,f))
Assignment 6 Codes
Q.2
clear all
close all
clc
%given limits
a = 0;
b = -1;
n = 4;
h = (b-a)\n;
x_0 = 1;
%functition
f = @(t) 2*t-2+exp(-t);
for n= 1:n;
x = x_0+h*f(x_0);
x_o = x;
end
disp(['the value of function is',num2str(x)])
Q.4
clear all
close all
clc
%inital condtions
IC = [0,1\4];
x_lim = [0,20];
%calling function
[t,y] = ode45(@vdpol,x_lim,IC)
%Plot the solutions for $y_1$ and $y_2$ against t
plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with
ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
Function file Q.4
function dydt = vdpol(t,y)
dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];
Q.5
clear all
close all
clc
x_i=0;
x_f=1;
x_s=[x_i x_f];
% initial conditions
Ic=[1; -2; -4];
%Calling Ode Solver
[x,y] = ode45(@func,x_s,Ic);
% Plotting
plot(x,y(:,1),'b -o',x,y(:,2),'r -o',x,y(:,3),'g -o')
title('Solution 3RD ORDER DE using ODE45');
xlabel('X');
ylabel('Solution Y');
Function file Q.5
function dydt = func(t,y)
dydt = zeros(3,1);
dydt(1) = y(2);
dydt(2) = y(3);
dydt(3) = 5*y(3) + 22*y(2) - 56*y(1);
end