50% found this document useful (6 votes)
5K views22 pages

Mth643 Solved Questions Lec01-08

This document contains solved questions from midterm exams on Introduction to MATLAB. It includes 16 questions covering various MATLAB topics like: 1) Using subs, sym, and solve commands to evaluate trigonometric, polynomial and parametric functions. 2) Plotting graphs of functions like sin, cos, exponentials on different intervals using commands like ezplot, plot, and hold. 3) Plotting parametric, contour and multiple curves. 4) Finding derivatives of functions using diff command and plotting multiple graphs of outputs. The questions provide examples of important MATLAB concepts and commands taught in the course for numerical computation and graphing. The document is intended as a study guide for students preparing for

Uploaded by

Khan
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
50% found this document useful (6 votes)
5K views22 pages

Mth643 Solved Questions Lec01-08

This document contains solved questions from midterm exams on Introduction to MATLAB. It includes 16 questions covering various MATLAB topics like: 1) Using subs, sym, and solve commands to evaluate trigonometric, polynomial and parametric functions. 2) Plotting graphs of functions like sin, cos, exponentials on different intervals using commands like ezplot, plot, and hold. 3) Plotting parametric, contour and multiple curves. 4) Finding derivatives of functions using diff command and plotting multiple graphs of outputs. The questions provide examples of important MATLAB concepts and commands taught in the course for numerical computation and graphing. The document is intended as a study guide for students preparing for

Uploaded by

Khan
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/ 22

MTH643 - INTRODUCTION TO MATLAB

From: ABU SULTAN


Page 1 of 22
Important and Solved Questions for Mid Term Exam
𝜋
L02_Q01: Find value of following trigonometric function at 𝑥 = 2 using subs command
Cos(x), Sin(x), Tan(x). (FOLLOW P#37-38 - LECT#02)
clear all
close all
clc
syms x a
a=cos(x)
subs(a,x,sym('pi/2'))
a=sin(x)
subs(a,x,sym('pi/2'))
a=tan(x)
subs(a,x,sym('pi/2'))
𝜋
L02_Q02: Find value of following trigonometric function at 𝑥 = using sym command
2
Cos(x), Sin(x), Tan(x). (FOLLOW P#37-38 - LECT#02)
close all
clear all
clc
cos(sym(pi/2))
sin(sym(pi/2))
tan(sym(pi/2))

L02_Q03: Find the value of the following using subs command. 𝑢 𝑥, 𝑦 = 2𝑥 + 𝑥𝑦 2 + 3𝑦


𝜋
at x=5, 𝑓 𝑥 = 𝑆𝑖𝑛 𝑥 𝑎𝑡 𝑥 = 2
(Follow P#036-42 - LECT#02)
(ABU SULTAN MID TERM Q#3(a) – 26 DEC 2019 – 12:00 pm)
clear all
close all
clc
syms x y u f
u=2*x+x*y^2+3*y;
subs(u,x,5)
f=sin(x)
subs(f,x,pi/2)

L02_Q04: Find the value of the following polynomials at x=2 using subs command.
𝑝 𝑥, 𝑦 = 𝑥 2 + 3𝑦 2 𝑥 + 10,𝑢 𝑥 = 𝑥 3 + 4𝑥 + 10 (Follow P#036-42 - LECT#02)
clear all
close all
clc
syms x y p u
p=x^2+3*y^2*x+10
subs(p,x,2)
u=x^3+4*x+10
subs(u,x,2)
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 2 of 22
Important and Solved Questions for Mid Term Exam
L03_Q05: Find the solution of 𝑥 2 − 𝑦 = 2 𝑎𝑛𝑑 𝑦 − 2𝑥 = 5 (P#066-68 - LECT#03)
close all
clear all
clc
syms x y
[x,y]=solve('x^2-y=2','y-2*x=5')
x(1)
y(1)

L03_Q06: Find solution of equation 2𝑥 3 + 𝑥 2 + 3𝑥 + 4 = 0 (FOLLOW P#066-68 -


LECT#03) (ABU SULTAN MID TERM Q#3(b) – 26 DEC 2019 – 12:00 pm)
close all
clear all
clc
syms x
solve('2*x^3+x^2+3*x+4=0')

L04_Q07: Solve by solve command. 2𝑥 + 7𝑦 = 3, 3𝑥 2 + 2𝑦 = 1. Also plot graph for


3𝑥 2 + 2𝑦 = 1. Name it parabola, give x-label and y-label also.
(FOLLOW P#066-71 - LECT#03) and (FOLLOW P#82,86 - LECT#04)
clc
close all
clear all
syms x y
solve('2*x+7*y=3','3*x^2+2*y=1')
ezplot('3*x^2+2*y=1',[-2,2])
xlabel('x-axis')
ylabel('y-axis')
title('Parabola')

L04_Q08: Plot the graph of 𝑒 −𝑥 𝑎𝑛𝑑 𝑆𝑖𝑛(𝑥) on the interval [0, 8] using ezplot, hold on and
hold off commands. Label the horizontal axis with x and vertical axis with y. Finally gives
the title “Multiple Graphs”. (P#90-92 - LECT#04)
%Plot the graph of e^(-x) and Sin(x)
%on the interval [0, 8] using ezplot, hold on and hold off commands.
%Label the horizontal axis with x and vertical axis with y.
%Finally gives the title “Multiple Graphs"
clc
clear all
close all
syms x
ezplot(exp(-x),[0,8])
hold on
ezplot(sin(x),[0,8])
hold off
xlabel('x')
ylabel('y')
title('Multiple Graphs')
grid
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 3 of 22
Important and Solved Questions for Mid Term Exam
L04_Q09: Plot the graph of 𝑒 −𝑥 𝑎𝑛𝑑 𝑆𝑖𝑛(𝑥) on the interval [0, 8] using plot, hold on and
hold off commands. Label the horizontal axis with x and vertical axis with y. Finally gives
the title “Multiple Graphs”. (P#90-92 - LECT#04)
%Plot the graph of e^(-x) and Sin(x)on the interval [0, 8] using plot, hold on and hold off.
%Label the horizontal axis with x and vertical axis with y.
%Finally gives the title “Multiple Graphs"
clc
clear all
close all
X=0:0.1:8;
plot(X,exp(-X))
hold on
plot(X,sin(X))
hold off
xlabel('x')
ylabel('y')
title('Multiple Graphs')
grid

L04_Q10: Plot the parametric graph of the circle with center at (0; 0), radius 1, and with
increment of 0:01 in the domain set. Label the horizontal axis with x and vertical axis with y.
Make the shape of the graph square. Keeps the title of the graph "Parametric plot of the
circle". (P#98-100 - LECT#04)
%Plot the parametric graph of the circle with center at (0; 0),
% with radius 1 and with increment of 0:01 in the domain set.
clc
clear all
close all
t=0:0.01:1;
plot(cos(2*pi*t),sin(2*pi*t))
xlabel('x')
ylabel('y')
title('Parametric Plot of the Circle')
grid

L04_Q11: Plot the contour plots of the expression x2 + y2 using meshgrid and contour
commands. Label the horizontal axis with x and vertical axis with y. Make the shape of the
graph square. Keeps the title of the graph "Contour plotting of squares".
(P#102-104 - LECT#04)
%Plot the contour plots of the expression x2 + y2 using meshgrid and contour commands.
%Label the horizontal axis with x and vertical axis with y.
%Make the shape of the graph square.
%Keeps the title of the graph "Contour plotting of squares".
clc
clear all
close all
[X,Y]=meshgrid(-2:0.1:2,-2:0.1:2);
contour(X,Y,X.^2+Y.^2)
axis square
xlabel('x')
ylabel('y')
title('Contour Plotting of Squares')
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 4 of 22
Important and Solved Questions for Mid Term Exam
L04_Q12: Plot the graph of 𝑥 3 + 𝑥 2 + 4 on the interval -2, 2] using ezplot, hold on and hold
off commands. Label the horizontal axis with x and vertical axis with y. Finally gives the title
“𝑥 3 + 𝑥 2 + 4”. (Follow P#90-92 - LECT#04)
%Plot the graph of x^3+x^2+4 on the interval -2, 2] using ezplot, hold on and hold off
commands.
%Label the horizontal axis with x and vertical axis with y.
%Finally gives the title “x^3+x^2+4”.
clc
clear all
close all
syms x
x=x^3+x^2+4
ezplot(x,[-2,2])
axis square
xlabel('x')
ylabel('y')
title('x^3+x^2+4')

L04_Q13: Plot the graph of the function sin(x) + cos(x) on the interval [0; 1], using plot
command. Label the horizontal axis with x and vertical axis with y. Make the shape of the
graph square. Keeps the title of the graph "The Graph of sin(x) + cos(x)". Keeps the layout of
the graph as grid. (Follow P#98-100 - LECT#04)
%Plot the graph of the function sin(x) + cos(x) on the interval [0; 1], using plot command.
%Label the horizontal axis with x and vertical axis with y.
%Make the shape of the graph square.
%Keeps the title of the graph "The Graph of sin(x) + cos(x)".
%Keeps the layout of the graph as grid.
clc
clear all
close all
X=0:0.01:1;
plot(X,(sin(X)+cos(X)))
xlabel('x')
ylabel('y')
axis square;
title('The Graph of sin(x) + cos(x)');
grid

L04_Q14: Plot the multiple curves of the functions sin(x) + cos(x) and e-x + x2 on the interval
[0; 4], using ezplot command. Label the horizontal axis with x and vertical axis with y. Make
the shape of the graph square. Keeps the title of the graph "The Graph of Multiple curves
using ezplot command ". Keeps the layout of the graph as grid.
(Follow P#90-92 - LECT#04)
%Plot the multiple curves of the functions sin(x) + cos(x) and e-x + x2
%on the interval [0; 4], using ezplot command.
%Label the horizontal axis with x and vertical axis with y.
%Make the shape of the graph square.
%Keeps the title of the graph "The Graph of Multiple curves using ezplot command ".
%Keeps the layout of the graph as grid.
clc
clear all
close all
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 5 of 22
Important and Solved Questions for Mid Term Exam
syms x
ezplot('sin(x)+cos(x)',[0,4])
hold on
ezplot('exp(-x)+x^2',[0,4])
xlabel('x')
ylabel('y')
axis square
title('The Graph of Multiple curves using ezplot command ')
grid

L04_Q15: Plot the contour plots of the circles x2+y2 of radius 1,2, 2, 3 .Label the
horizontal axis with x and vertical axis with y. Make the shapes of the graph square. Keeps
the title of the graph “Contour Plots of Circles”. Keeps the layout of the graph grid.
(P#109 - EXERCISE – LECT#04)
%Plot the contour plots of the circles x2+y2 of radius 1,2,?2,?3
%Label the horizontal axis with x and vertical axis with y.
%Make the shapes of the graph square.
%Keeps the title of the graph “Contour Plots of Circles”.
%Keeps the layout of the graph grid.
clc
clear all
close all
syms a b
[X,Y]=meshgrid(-2:0.1:2,-2:0.1:2);
contour(X,Y,X.^2+Y.^2-1);
contour(X,Y,X.^2+Y.^2-2);
contour(X,Y,X.^2+Y.^2-sqrt(2));
contour(X,Y,X.^2+Y.^2-sqrt(3));
axis square
xlabel('x-axis')
ylabel('y-axis')
title('Contour Plots of Circles')
grid

L04_Q16: Plot the graph of sin(x)+cos(x) and e(-x)+x^2 on the interval [0, 4] using plot,
hold on and without use of hold on and hold off commands. Label the horizontal axis with x
and vertical axis with y. Finally gives the title “The Graph of Multiple Curves using plot
command".(P#108 - EXERCISE – LECT#04)
%Plot the graph of sin(x)+cos(x) and exp(-x)+x^2
%on the interval [0, 4] using plot command and without use of hold on and hold off
commands.
%Label the horizontal axis with x and vertical axis with y.
%Finally gives the title “The Graph of Multiple Curves using plot command".
%Keeps the layout of the graph as grid.
clc
clear all
close all
x=0:0.1:4;
f1=sin(x)+cos(x);
f2=exp(-x)+x.^2
plot(x,f1,x,f2)
xlabel('x')
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 6 of 22
Important and Solved Questions for Mid Term Exam
ylabel('y')
title('The Graph of Multiple Curves using plot command')
grid

L05_Q17: Find the first-order, second-order, and fourth-order derivatives of the function
𝑓 𝑥 = 𝑥10 + 2 ∗ 𝑥 2 + 𝑆𝑖𝑛 𝑥 Using diff command. Plot the multiple graphs of the
outputs using ezplot command on the interval [-𝜋, 𝜋]. Label the horizontal axis with x and
vertical axis with y. Keeps the title "Multiple plot of the function and its derivatives". All the
coding should be written using Script M–File.
(P#144 - EXERCISE – LECT#05)+ (P#174 - EXERCISE – LECT#06)
%Find the first-order, second-order, and fourth-order derivatives of the
functionf(x)=x^10+2*(x^2 )+Sin (x) Using diff command.
%Plot the multiple graphs of the outputs using ezplot command on the interval [-?,?].
%Label the horizontal axis with x and vertical axis with y.
%Keeps the title "Multiple plot of the function and its derivatives".
%All the coding should be written using Script M–File
clc
clear all
close all
syms x
f=x^10+2*x^2+sin(x);
f1=diff(f,1)
f2=diff(f,2)
f4=diff(f,4)
ezplot(f,[-pi,pi])
hold on
ezplot(f1,[-pi,pi])
hold on
ezplot(f4,[-pi,pi])
hold off
xlabel('x-axis')
ylabel('y-axis')
title('Multiple plot of the function and its derivatives')
grid

L05_Q18: Find the first-order, fourth-order, and fifth-order derivatives of the function
𝑓 𝑥 = 𝐼𝑛 𝑥 + 𝑆𝑖𝑛(𝑥) using diff command. Plot the multiple graphs of the outputs using plot
command on the interval [0, 1] and without using hold on and hold off commands Label the
horizontal axis with x and vertical axis with y. Keeps the title "Multiple plot of the function
and its derivatives". All the coding should be written using Script M–File.
(P#145 - EXERCISE – LECT#05) + (P#175 - EXERCISE – LECT#06)
%Find the first-order, fourth-order, and fifth-order derivatives of the function
%f(x)=In x+Sin(x)using diff command.
%Plot the multiple graphs of the outputs using plot command on the interval [0, 1]
%and without using hold on and hold off commands.
%Label the horizontal axis with x and vertical axis with y.
%Keeps the title "Multiple plot of the function and its derivatives".
%All the coding should be written using Script M–File
clc
close all
clear all
syms x
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 7 of 22
Important and Solved Questions for Mid Term Exam
f=log(x)+sin(x)
f1=diff(f,1)
f4=diff(f,4)
f5=diff(f,5)
x=0:0.1:1;
f11=eval(vectorize(f1));
f44=eval(vectorize(f4));
f55=eval(vectorize(f5));
plot(x,f11,x,f44,x,f55)
xlabel('x-axis')
ylabel('y-axis')
title('Multiple plot of the function and its derivatives')
grid

L05_Q19: Find the first-order, fourth-order, and fifth-order derivatives of the function
𝑓 𝑥 = 𝐼𝑛 𝑥 ∗ 𝑦 + 𝑆𝑖𝑛(𝑥 2 ) using diff command. Plot the multiple graphs of the outputs using
plot command on the interval [0, 1] and without using hold on and hold off commands Label
the horizontal axis with x and vertical axis with y. Keeps the title "Multiple plot of the
function and its derivatives". All the coding should be written using Script M–File.
(P#145 - EXERCISE – LECT#05) + (P#176 - EXERCISE – LECT#06)
%Find the first-order, fourth-order, and fifth-order derivatives of the function
%f(x)=In x*y+Sin(x^2) using diff command.
%Plot the multiple graphs of the outputs using plot command on the interval [0, 1]
%and without using hold on and hold off commands.
%Label the horizontal axis with x and vertical axis with y.
%Keeps the title "Multiple plot of the function and its derivatives".
%All the coding should be written using Script M–File
clc
clear all
close all
syms x y
f=log(x*y)+sin(x^2)
d1=diff(f,1)
d4=diff(f,4)
d5=diff(f,5)
x=0:0.1:1;
d11=eval(vectorize(d1));
d44=eval(vectorize(d4));
d55=eval(vectorize(d5));
plot(x,d11,x,d44,x,d55)
xlabel('x-axis')
ylabel('y-axis')
grid
title('Multiple plot of the function and its derivatives')

L05_Q20: Find the derivative of the following function with respect to x, and t variables
using diff command. Moreover plot the multiple graph of the function and their derivatives
by defining X and Y using meshgrid command, Then define Z and create a surface plot:
2 2
f x, t = xe−x −t x, t ∈ −2,2 .
(P#122 – LECT#05)
%Find the derivative of the following function with respect to x, and t variables using diff
command.
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 8 of 22
Important and Solved Questions for Mid Term Exam
%Moreover plot the multiple graph of the function and their derivatives by defining X and Y
using meshgrid command.
%Then define Z and create a surface plot:
%function is f(x,t)=xe^(-x^2-t^2 ) x,t?[-2,2]
clc
clear all
close all
syms x t
f=x*exp(-x^2-t^2);
f1=diff(f,x)
f2=diff(f,t)
[x,t]=meshgrid(-2:0.2:2,-2:0.2:2);
ff=eval(vectorize(f));
f11=eval(vectorize(f1));
f22=eval(vectorize(f2));
surf(x,t,ff)
hold on
surf(x,t,f11)
hold on
surf(x,t,f22)
hold off

L05_Q21: Find the first-order, second-order, and fourth-order derivatives of the function
f x = 2xy + (xy)3 with respect to variable y using diff command.
%Find the first-order, second-order, and fourth-order derivatives of the function
%f(x)=2xy+(xy)^3 with respect to variable y using diff command.
syms x y
f=2*x*y+(x*y)^3
diff(f,y,1)
diff(f,y,2)
diff(f,y,4)

L05_Q22: Find the integral of the function f x = x 2 + 10x + 4 using int command. Plot the
multiple graphs of the function and its output using plot command. Label the horizontal axis
with x and vertical axis with y. Keeps the title "Graph of function and its integral"
%Find the integral of the function f(x)=x^2+10x+4 using int command.
%Plot the multiple graphs of the function and its output using plot command.
%Label the horizontal axis with x and vertical axis with y.
%Keeps the title "Graph of function and its integral"
clc
clear all
close all
syms x
f=int(x^2+10*x+4)
x=-2:0.01:2;
plot(x,x.^2+10.*x+4,(x.*(x.^2 + 15.*x + 12))./3,x)
xlabel('x-axis')
ylabel('y-axis')
title('Graph of function and its integral')
grid
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 9 of 22
Important and Solved Questions for Mid Term Exam
L05_Q23: Differentiate the following functions using diff command. Moreover plot the
multiple graphs of the given functions and their derivatives on the interval [0, 5]. f x = x 2 +
2x + 10 and g x = sin x (P#116 – LECT#05)
%Differentiate the following functions using diff command.
%Moreover plot the multiple graphs of the given functions and their derivatives on the
interval [0, 5].
%f(x)=x^2+2x+10 and g(x)=sin(x)
clc
clear all
close all
syms x
f=x^2+2*x+10
g=sin(x)
f1=diff(f)
g1=diff(g)
x=0:0.1:5;
plot(x,(x.^2+2.*x+10),x,(2.*x + 2),x,sin(x),x,cos(x))
xlabel('x-axis')
ylabel('y-axis')
title('Graph of function and its derivatives using diff and plot')
grid

L06_Q24: Compute the values of sin(x) at x = 0; 1, and 2 using for loop.


(P#170 – LECT#06)
%Compute the values of sin(x) at x = 0; 1, and 2 using for loop.
clear all
close all
clc
for i=1:5
y=sin(i)
end

L06_Q25: Solve the following algebraic equations using Script M-Files.


𝑥 2 + 2𝑥 − 4 = 0 and 𝑥 3 + 5𝑥 2 + 4𝑥 + 3 = 0
Solve the following equations for x using Script M-Files.
𝑥 + log 𝑦 = 3 and 𝑥 + 10𝑦 = 6
Solve the following system of equations using Script M-Files.
𝑥 + 𝑦 2 = 2, 𝑦 − 3𝑥 = 7 and 𝑥 + 𝑦 2 = 2, 2𝑦 2 − 3𝑥 = 7
(P#173 - EXERCISE – LECT#06)
%Solve the following algebraic equations using Script M-Files.
%x^2+2x-4=0 and x^3+5x^2+4x+3=0
%Solve the following equations for x using Script M-Files. %x+log(y)=3 and x+10y=6
%Solve the following system of equations using Script M-Files.
%x+y^2=2,y-3x=7 and x+y^2=2,2y^2-3x=7
clear all
close all
clc
syms x y
[x]=solve('x^2+2*x-4=0','x^3+5*x^2+4*x+3=0')
[x,y]=solve('x+log(y)=3','x+10*y=6');
[x,y]=solve('x+y^2=2','y-3*x=7');
[x,y]=solve('x+y^2=2','2*y^2-3*x=7');
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 10 of 22
Important and Solved Questions for Mid Term Exam
MIX_Q26: Find the first and second derivative of the following function with respect to x
using MATLAB command. Then create a surface plot of the given function and its first and
second derivatives by defining X and Y using mesh grid command with hold on and hold off
command. 𝑓 𝑥, 𝑦 = 𝑥𝑦 𝑥 2 − 𝑦 2 . (ASSIGNMENT#01)
% ASSIGNMENT#1 BY ME
% FIND FIRST & SECOND DERIVATIVES OF f(x,y)=xy(x^2-y^2) w.r.t x.
% Then create surface plot of given function, its first & second derivatives using
% meshgrid command with hold on and hold off comman.
clear all;
clc;
close all;
syms x y;
f=x*y*(x^2-y^2)
df=diff(f)
ddf=diff(df)
u=-2:0.1:2;
v=-2:0.1:2;
[x,y]=meshgrid(u,v);
f=eval(vectorize(f));
df=eval(vectorize(df));
ddf=eval(vectorize(ddf));
surf(x,y,f)
hold on
surf(x,y,df)
hold on
surf(x,y,ddf)
hold off

MIX_Q27: Solve: f x, y = xy 2 + 2x + 4 = 0, f x, y = 3x 2 y + 2xy 2 + 4x at x=5,


f x = Sin x at x = 5
%Solve: f(x,y)=xy^2+2x+4=0 , f(x,y)=3x^2y+2xy^2+4x at x=5
%f(x)=Sin x at x=5
clc
clear all
close all
syms x y u v
[x,y]=solve('x*y^2+2*x+4=0')
u=3*x^2*y+2*x*y^2+4*x;
subs(u,x,5)
v=sin(x);
subs(v,x,5)

MIX_Q28: Plot the contour plots of the Sin(x) +Cos(y) where x range from −2𝜋 𝑡𝑜 2𝜋, y
range from 0 𝑡𝑜 4𝜋. Label the horizontal axis with x and vertical axis with y. Keep the title of
the graph “Contour Plot of Sin(X)+Cos(Y).
%Plot the contour plots of the Sin(x) +Cos(y)
%where x range from -2? to 2?, y range from 0 to 4?.
%Label the horizontal axis with x and vertical axis with y.
%Keep the title of the graph “Contour Plot of Sin(X)+Cos(Y).
clc
clear all
close all
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 11 of 22
Important and Solved Questions for Mid Term Exam
syms x y
[X,Y]=meshgrid(-2*pi:0.01:2*pi,0:0.01:4*pi);
contour(X,Y,sin(X)+cos(Y))
xlabel('x-axis');
ylabel('y-axis');
title('Contour Plot of Sin(X)+Cos(Y)')
grid

L07_Q29: Find the solution of the following initial value problem dy/dx = x 2 + y; y(1) = 3.
Moreover, plot the graph of the solution using ezplot command on the interval [0,2].
(P#187-189 - EXERCISE – LECT#07)
%Find the solution of the following initial value problem dy/dx = x2 + y; y(1) = 3.
%Moreover, plot the graph of the solution using ezplot command on the interval [0,2].
clc
clear all
close all
syms y
eq1='Dy=x^2+y';
y=dsolve(eq1,'y(1)=3','x')
ezplot(y,[0,2])
xlabel('x-axis')
ylabel('y-axis')
title('Solution of Initial Value Problem and ezplot of solution')
grid

L07_Q30: Find general solution of the following boundary value problem y′′ x + 8y ′ x +
2y x = cos⁡ (x). Then plot the solution curve on the interval [0,4] corresponding to the
following boundary condtions. y 0 = 4, y′ 1 = 5.
(P#215 - EXERCISE – LECT#07)
%Find general solution of the following boundary value problem y''x)+8y'(x)+2y(x)=cos(x).
%Then plot the solution curve on the interval [0,4]
%corresponding to the following boundary condtions. y(0)=4,y'(1)=5.
clc
clear all
close all
%syms x y
eq1='D2y+8*Dy+2*y=cos(x)';
icon='y(0)=4,Dy(1)=5';
y=dsolve(eq1,icon,'x')
ezplot(y,[0,4])
xlabel('x-axis')
ylabel('y-axis')
title('Solution of Boundary Value Problem and Solution Curve')
grid

L07_Q31: Plot the family of curves of the following differential equation on the interval
[0,3], with initial values y(0) = -3 : 3, dy/dx = x * y + 2 * x2.
(P#194-196 - EXERCISE – LECT#07)
%Plot the family of curves of the following differential equation on the interval [0,3].
%with initial values y(0) = -3 : 3, dy/dx = x * y + 2 * x2.
clc
clear all
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 12 of 22
Important and Solved Questions for Mid Term Exam
close all
eq1='Dy=x*y+2*x^2';
y=dsolve(eq1,'y(0)=c','x')
figure; hold on
for cval=-3:3
ezplot(subs(y,'c',cval),[0,3])
end
xlabel('x-axis')
ylabel('y-axis')
title('Family of Curves of DE')
grid

L07_Q32: Find the general solution of the following differential equation y ′ x = 2xy + 2x 3
. Also plot the family of solution curves on the interval [-4,4] of above differential equation
obtained using the following initial conditions y(0) = -3,-2-1,0,1,2,3.
(P#214 - EXERCISE – LECT#07)
%Find the general solution of the following differential equation y'(x)=2xy+2x^3.
%Also plot the family of solution curves on the interval [-4,4] of above differential equation
%obtained using the following initial conditions y(0) = -3,-2-1,0,1,2,3.
clc
clear all
close all
eq1='Dy=2*x*y+2*x^3';
y=dsolve(eq1,'y(0)=c','x')
figure; hold on
for cval=-3:3
ezplot(subs(y,'c',cval),[-4,4])
end
xlabel('x-axis')
ylabel('y-axis')
title('Family of Curves of DE')
grid

L07_Q33: Solve the following second-order differential equation y ′′ x + y ′ x − 6y =


0 subject to the following initial conditions y 0 = 1, y ′ 0 = 0. Moreover plot the solution
curve on the interval [0,2]. (P#198-200 - EXERCISE – LECT#07)
%Solve the following second-order differential equation y''(x)+y'(x)-6y=0
%subject to the following initial conditions y(0)=1,y'(0)=0.
%Moreover plot the solution curve on the interval [0,2]
clc
clear all
close all
eq1='D2y+Dy-6*y=0';
incond='y(0)=1,Dy(0)=0';
y=dsolve(eq1,incond,'x')
ezplot(y,[0,2])
xlabel('x-axis')
ylabel('y-axis')
title('Solution of 2nd Order DE')
grid
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 13 of 22
Important and Solved Questions for Mid Term Exam
L07_Q34:Solve the following second-order differential equation y ′′ x + y ′ x − 6y =
0 subject to the following initial conditions y 0 = 1, y ′ 1 = 0. Moreover plot the solution
curve on the interval [0,3]. (P#201-203 - EXERCISE – LECT#07)
%Solve the following second-order differential equation y''(x)+y'(x)-6y=0
%subject to the following initial conditions y(0)=1,y'(1)=0.
%Moreover plot the solution curve on the interval [0,3].
clc
clear all
close all
eq1='D2y+Dy-6*y=0';
incond='y(0)=1,Dy(1)=0';
y=dsolve(eq1,incond,'x')
ezplot(y,[0,3])
xlabel('x-axis')
ylabel('y-axis')
title('Solution of 2nd Order DE')
grid

L07_Q35: Solve the following system of differential equations by using dsolve command.
x ′ t = x t + 2y t − z t
y′ t = x t + z t
z ′ t = 4x t − 4y t + 5z t
(P#204-205 - EXERCISE – LECT#07)
%Solve the following system of differential equations by using dsolve.
%x'(t)=x(t)+2y(t)-z(t)
%y'(t)=x(t)+z(t)
%z'(t)=4x(t)-4y(t)+5z(t)
eq1='Dx=x+2*y-z';
eq2='Dy=x+z';
eq3='Dz=4*x-4*y+5*z';
[x,y,z]=dsolve(eq1,eq2,eq3)

L07_Q36: Solve the following system of differential equations.


x ′ t = x t + 2y t − z t
y′ t = x t + z t
z ′ t = 4x t − 4y t + 5z t
Corresponding to the following conditions x(0)=1,y(0)=2,z(0)=3. Moreover plot the solution
curves using the plot command. (P#206-209 - EXERCISE – LECT#07)
%Solve the following system of differential equations.
%x'(t)=x(t)+2y(t)-z(t)
%y'(t)=x(t)+z(t)
%z'(t)=4x(t)-4y(t)+5z(t)
%Corresponding to the following conditions x(0)=1,y(0)=2,z(0)=3
%Moreover plot the solution curves using the plot command
%Solve the following system of differential equations.
%x'(t)=x(t)+2y(t)-z(t)
%y'(t)=x(t)+z(t)
%z'(t)=4x(t)-4y(t)+5z(t)
%Corresponding to the following conditions x(0)=1,y(0)=2,z(0)=3
%Moreover plot the solution curves using the plot command
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 14 of 22
Important and Solved Questions for Mid Term Exam
clc
clear all
close all
eq1='Dx=x+2*y-z';
eq2='Dy=x+z';
eq3='Dz=4*x-4*y+5*z';
incond='x(0)=1,y(0)=2,z(0)=3';
[x,y,z]=dsolve(eq1,eq2,eq3,incond)
t=linspace(0,0.5,25);
xx=eval(vectorize(x));
yy=eval(vectorize(y));
zz=eval(vectorize(z));
plot(t,xx,t,yy,t,zz)
xlabel('x-axis')
ylabel('y-axis')
title('Graph of solution curves of DE')
grid

L07_Q37: Solve the following system of differential equations.


x ′′ (t) = x ′ t + 2y ′ t − z ′ t
y ′′ t = x ′ (t) + z ′ t
z t = 4 x ′ t − 4y ′ t + 5 z ′ t
′′

Corresponding to the following conditions x 0 = 1, x ′ 0 = 2, y 0 = 1, y ′ 0 =


2, z 0 = 3, z ′ 0 = 4.
Moreover plot the solution curves using the plot command.
(P#210-213 - EXERCISE – LECT#07)
%Solve the following system of differential equations.
%x''(t)=x'(t)+2y'(t)-z'(t)
%y''(t)=x'(t)+z'(t)
%z''(t)=4x'(t)-4y(t)+5z'(t)
%Corresponding to the following conditions x(0)=1,x'(0)=2,y(0)=1,y'(0)=2,z(0)=3,z'(0)=4.
%Moreover plot the solution curves using the plot command.
clc
clear all
close all
eq1='D2x=Dx+2*y-Dz';
eq2='D2y=Dx+Dz';
eq3='D2z=4*Dx-4*y+5*z';
incond='x(0)=1,Dx(0)=2,y(0)=1,Dy(0)=2,z(0)=3,Dz(0)=4';
[x,y,z]=dsolve(eq1,eq2,eq3,incond)
t=linspace(0,5,25);
xx=eval(vectorize(x));
yy=eval(vectorize(y));
zz=eval(vectorize(z));
plot(t,xx,t,yy,t,zz)
xlabel('x-axis')
ylabel('y-axis')
title('Graph of solution curves of DE')
grid
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 15 of 22
Important and Solved Questions for Mid Term Exam
L07_Q38: Solve the following system of differential equations.
x ′′ (t) = 2x ′ t + 2y ′ t − z ′ t
y ′′ t = 3x ′ t − 3z ′ t
z t = 5 x ′ t − 4y ′ t + 5 z ′ t
′′

Corresponding to the following conditions x 0 = 2, x ′ 0 = 1, y 0 = 3, y ′ 0 =


4, z 0 = 3, z ′ 0 = 5 (P#216 - EXERCISE – LECT#07)
%Solve the following system of differential equations.
%x''(t)=2x'(t)+2y'(t)-z'(t)
%y''(t)=3x'(t)-3z'(t)
%z''(t)=5x'(t)-4y'(t)+5z't)
%Corresponding to the following conditions x(0)=2,x'(0)=1,y(0)=3,y'(0)=4,z(0)=3,z'(0)=5
clc
clear all
close all
eq1='D2x=2*Dx+2*Dy-Dz'
eq2='D2y=3*Dx-3*Dz';
eq3='D2z=5*Dx-4*Dy+5*Dz';
incond='x(0)=2,Dx(0)=1,y(0)=3,Dy(0)=4,z(0)=3,Dz(0)=5';
[x,y,z]=dsolve(eq1,eq2,eq3,incond)
t=linspace(0,5,25);
xx=eval(vectorize(x));
yy=eval(vectorize(y));
zz=eval(vectorize(z));
plot(t,xx,t,yy,t,zz)
xlabel('x-axis')
ylabel('y-axis')
title('Graph of solution curves of DE')
grid

L07_Q39: Solve the following system of differential equations.


x ′ t = 2x t + 2y t − 3z t
y ′ t = 2x t + 3z t

z t =x t −y t +z t
Corresponding to the following conditions x(0)=2,y(0)=1,z(0)=4. Moreover plot the solution
curves using plot command. (P#217 - EXERCISE – LECT#07)
%Solve the following system of differential equations.
%x'(t)=2x(t)+2y(t)-3z(t)
%y'(t)=2x(t)+3z(t)
%z'(t)=x(t)-y(t)+z(t)
%Corresponding to the following conditions x(0)=2,y(0)=1,z(0)=4.
%Moreover plot the solution curves using plot command.
clc
clear all
close all
eq1='Dx=2*x+2*y-3*z'
eq2='Dy=2*x+3*z';
eq3='Dz=x-y+z';
incond='x(0)=2,y(0)=1,z(0)=4';
[x,y,z]=dsolve(eq1,eq2,eq3,incond)
t=linspace(0,5,25);
xx=eval(vectorize(x));
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 16 of 22
Important and Solved Questions for Mid Term Exam
yy=eval(vectorize(y));
zz=eval(vectorize(z));
plot(t,xx,t,yy,t,zz)
xlabel('x-axis')
ylabel('y-axis')
title('Graph of solution curves of DE')
grid

L08_Q40: Find Numerical solution of the following differential equation on the interval [0.1]
𝑑𝑦
using Euler’s Formula for n=10, 𝑑𝑥 = 𝑆𝑖𝑛 𝑥𝑦 , 𝑦 0 = 𝜋 (P#225-229 – LECT#08)
function [xvalues,yvalues]=euler(f,x0,y0,xn,n);
format long
x0=0;
y0=pi;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
xn=1;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+sin(x(k)*y(k))*dx;
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)

L08_Q41: Find the numerical solution of the following differential equation on the interval
𝑑𝑦 𝑦 −𝑥
[0; 1] using Euler’s method for n = 20. 𝑑𝑥 = 𝑦 +𝑥 , 𝑦 0 = 0.5
(FOLLOW P#225-229 – LECT#08)
%Find the numerical solution of the following differential equation on the interval [0,1]
%using Euler’s method for n = 20. dy/dx=(y-x)/(y+x) ,y(0)=0.5
function [xvalues,yvalues]=euler(f,x0,y0,xn,n);
format long
x0=0;
y0=0.5;
xn=1;
n=20;
x(1)=x0;
y(1)=y0;
xn=1;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+((y(k)-x(k))/(y(k)+x(k)))*dx;
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 17 of 22
Important and Solved Questions for Mid Term Exam
L08_Q42: Find the numerical solution of the following differential equation on the interval
𝑑𝑦
[0; 1] using improved Euler’s Formula for n=10, 𝑑𝑥 = 𝑆𝑖𝑛 𝑥𝑦 , 𝑦 0 = 𝜋
(P#231-235 – LECT#08)
%Find the numerical solution of the following differential equation on the interval [0,1]
%using improved Euler’s Formula for n=10, dy/dx=Sin(xy),y(0)=?
function [xvalues,yvalues]=impeuler(f,x0,y0,xn,n);
format long
f=@(x,y)sin(x.*y);
x0=0;
y0=pi;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
xn=1;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+dx/2*(f(x(k),y(k))+f(x(k),y(k)+dx*y(k)));
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)

L08_Q43: Find the numerical solution of the following differential equation on the interval
𝑑𝑦 𝑦 −𝑥
[0,1] using Improved Euler’s method for n = 20. 𝑑𝑥 = 𝑦 +𝑥 , 𝑦 0 = 0.5
(FOLLOW P#231-235 – LECT#08)
%Find the numerical solution of the following differential equation on the interval [0,1]
%using Improved Euler’s method for n = 20. dy/dx=(y-x)/(y+x) ,y(0)=0.5
function [xvalues,yvalues]=impeuler(f,x0,y0,xn,n);
format long
f=@(x,y)((y-x)/(y+x));
x0=0;
y0=1;
xn=0.5;
n=20;
x(1)=x0;
y(1)=y0;
xn=1;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+dx/2*(f(x(k),y(k))+f(x(k),y(k)+dx*y(k)));
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 18 of 22
Important and Solved Questions for Mid Term Exam
L08_Q44: Find the numerical solution of the following initial value problem on the interval
[0,1] using improved Euler’s method by taking step size ∆𝑡 = 0.01, Moreover, plot the graph
𝑑𝑦 𝑦−𝑡
of the approximated solution curve. 𝑑𝑡 = 𝑦+𝑡 , 𝑦 0 = 0.5
Note: The iterative form of the improved Euler’s method is given below;
∆𝑡 ′
𝑦𝑘+1 ≈ 𝑦𝑘 + 𝑦 + 𝑓(𝑡𝑘+1 , 𝑦𝑘 + ∆𝑡𝑦𝑘′ ), 𝑘 = 0,1,2, … … 𝑛 − 1
2 𝑘
(FOLLOW P#231-235 – LECT#08) –
(ABU SULTAN MID TERM Q#1 – 26 DEC 2019 – 12:00 pm)
%Find the numerical solution of the following initial value problem on the interval [0,1]
%using improved Euler’s method by taking step size ∆t=0.01,
%Moreover, plot the graph of the approximated solution curve. dy/dt=(y-t)/(y+t) ,y(0)=0.5
function [yvalues,tvalues]=impeuler(f,y0,t0,yn,n);
format long
f=@(y,t)((y-t)/(y+t));
y0=0;
t0=1;
yn=0.5;
n=20;
y(1)=y0;
t(1)=t0;
yn=1;
dt=0.01;
for k=1:n
y(k+1)=y(k)+dt;
t(k+1)=t(k)+dt/2*(f(y(k),t(k))+f(y(k),t(k)+dt*t(k)));
end
yvalues=y'
tvalues=t'
plot(yvalues,tvalues)

L08_Q45: Find the numerical solution of the following differential equation on the interval
dy
[0, 1] using Runge–Kutta method of fourth order for n=10, dx = Sin xy , y 0 = π
(SOLUTION P#237-244 - LECT#08)
%Find the numerical solution of the following differential equation on the interval [0,1]
%using Runge–Kutta method of fourth order for n=10, dy/dx=Sin(xy),y(0)=?
function [xvalues,yvalues]=RungeKutta(f,x0,y0,xn,n);
format long
f=@(x,y)sin(x.*y);
x0=0;
y0=pi;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
k1=f(x(k),y(k));
k2=f(x(k)+dx/2,y(k)+dx/2*(k1));
k3=f(x(k)+dx/2,y(k)+dx/2*(k2));
k4=f(x(k+1),y(k)+dx+(k3));
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 19 of 22
Important and Solved Questions for Mid Term Exam
y(k+1)=y(k)+dx/6*(k1+2*k2+2*k3+k4);
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Runge Kutta Method of order four');
grid;
xlabel('x-axis');
ylabel('y-axis');

𝑑𝑦
L08_Q46: = 𝐶𝑜𝑠 𝑥 + 𝑦 , 𝑛 = 10, 0,1 , 𝑦 0 = 𝑝𝑖. Solve by using Range-kutta method.
𝑑𝑥
(FOLLOW SOLUTION P#237-244 - LECT#08)
% dy/dx=Cos(x+y),n=10,[0,1],y(0)=pi
% Solve by using Range-kutta method.
function [xvalues,yvalues]=RungeKutta(f,x0,y0,xn,n);
format long
f=@(x,y)cos(x+y);
x0=0;
y0=pi;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
k1=f(x(k),y(k));
k2=f(x(k)+dx/2,y(k)+dx/2*(k1));
k3=f(x(k)+dx/2,y(k)+dx/2*(k2));
k4=f(x(k+1),y(k)+dx+(k3));
y(k+1)=y(k)+dx/6*(k1+2*k2+2*k3+k4);
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Runge Kutta Method of order four');
grid;
xlabel('x-axis');
ylabel('y-axis');

L08_Q47: Find the numerical solution of the following differential equation on the interval
𝑑𝑦 𝑦 −𝑥
[0,1] using Runge–Kutta method of fourth order for n = 20 𝑑𝑡 = 𝑦 +𝑥 , 𝑦 0 = 0.5
(FOLLOW SOLUTION P#237-244 - LECT#08)
% Find the numerical solution of the following differential equation on
% the interval [0, 1] using Runge–Kutta method of fourth order for n = 20
% dy/dt=(y-x)/(y+x) ,y(0)=0.5
function [xvalues,yvalues]=RungeKutta(f,x0,y0,xn,n);
format long
f=@(x,y)((y-x)/(y+x));
x0=0;
y0=0.5;
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 20 of 22
Important and Solved Questions for Mid Term Exam
xn=1;
n=20;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
k1=f(x(k),y(k));
k2=f(x(k)+dx/2,y(k)+dx/2*(k1));
k3=f(x(k)+dx/2,y(k)+dx/2*(k2));
k4=f(x(k+1),y(k)+dx+(k3));
y(k+1)=y(k)+dx/6*(k1+2*k2+2*k3+k4);
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Runge Kutta Method of order four');
grid;
xlabel('x-axis');
ylabel('y-axis');

L08_Q48: Find Numerical solution of the following differential equation on the interval [0,1]
𝑑𝑦
using Taylor’s Formula for n=10, = 𝑆𝑖𝑛 𝑥𝑦 , 𝑦 0 = 𝜋
𝑑𝑥
(SOLUTION P#245-250 - LECT#08)
%rical solution of the following differential equation on the interval
%[0,1] using Taylor’s Formula for n=10, dy/dx=Sin(xy),y(0)=?
function [xvalues,yvalues]=TaylorOrder(f,x0,y0,xn,n);
format long
f=@(x,y)sin(x.*y);
x0=0;
y0=pi;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+f(x(k),y(k))*dx+(y(k)*cos(x(k)*y(k))+x(k)*cos(x(k)*y(k))*f(x(k),y(k)))*(dx)^2
/2;
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Taylor’s Method of Second Order');
grid;
xlabel('x-axis');
ylabel('y-axis');
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 21 of 22
Important and Solved Questions for Mid Term Exam
L08_Q49: Find the numerical solution of the following differential equation on the interval
dy y−x
[0,1] using Taylor’s method of second order for n = 20. dx = y+x , y 0 = 0.5
(FOLLOW SOLUTION P#245-250 - LECT#08)
%Find the numerical solution of the following differential equation on
% the interval [0,1] using Taylor’s method of second order for n = 20.
%dy/dx=(y-x)/(y+x) ,y(0)=0.5
function [xvalues,yvalues]=TaylorOrder(f,x0,y0,xn,n);
format long
f=@(x,y)((y-x)/(y+x));
x0=0;
y0=0.5;
xn=1;
n=20;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+f(x(k),y(k))*dx+(y(k)*cos(x(k)*y(k))+x(k)*cos(x(k)*y(k))*f(x(k),y(k)))*(dx)^2
/2;
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Taylor’s Method of Second Order');
grid;
xlabel('x-axis');
ylabel('y-axis');

𝑑𝑦
L08_Q50: Solve by Taylor method 𝑑𝑥 = 𝐶𝑜𝑠 𝑥𝑦 , 𝑦 0 = 1, ℎ𝑒𝑟𝑒 𝑛 = 10 𝑜𝑟𝑑𝑒𝑟.
(FOLLOW SOLUTION P#245-250 - LECT#08)
%Solve by Taylor method dy/dx=Cos(xy),y(0)=1,here n=10 order
function [xvalues,yvalues]=TaylorOrder(f,x0,y0,xn,n);
format long
f=@(x,y)cos(x.*y);
x0=0;
y0=1;
xn=1;
n=10;
x(1)=x0;
y(1)=y0;
dx=(xn-x0)/n;
for k=1:n
x(k+1)=x(k)+dx;
y(k+1)=y(k)+f(x(k),y(k))*dx+(y(k)*cos(x(k)*y(k))+x(k)*cos(x(k)*y(k))*f(x(k),y(k)))*(dx)^2
/2;
end
xvalues=x'
yvalues=y'
plot(xvalues,yvalues)
title('Taylor’s Method of Second Order');
MTH643 - INTRODUCTION TO MATLAB
From: ABU SULTAN
Page 22 of 22
Important and Solved Questions for Mid Term Exam
grid;
xlabel('x-axis');
ylabel('y-axis');

MIX_Q51: Find the solution of the following second order differential equation
𝑦 ′′ 𝑡 + 8𝑦 ′ 𝑡 + 2𝑦 𝑥 = 𝐶𝑜𝑠(𝑥). (PAST PAPERS)
%Find the solution of the following second order differential equation
%y''(t)+8y'(t)+2y(x)=Cos(x).
clc
clear all
close all
eq1='D2y+8*Dy+2*y(x)=cos(x)'
dsolve(eq1,'t')

MIX_Q52: Plto the contour plots of the expression z=x*exp(-x^2-y^2) range is -2<x<2 and -
3<y<3. Label teh horizontal axis with x and vertical axis with y. keep the title of graph
contour plots of the expression.
(ABU SULTAN MID TERM Q#2 – 26 DEC 2019 – 12:00 pm)

%Plto the contour plots of the expression z=x*exp(-x^2-y^2)


%range is -2<x<2 and -3<y<3
%Label teh horizontal axis with x and vertical axis with y
%keep the title of graph contour plots of the expression
clc
clear all
close all
syms x y
[X,Y]=meshgrid(-2:0.5:2,-3:0.5:3);
contour(X,Y,X.*exp(-X.^2-Y.^2));
xlabel('x-axis');
ylabel('y-axis');
title('Graph of Contour plots of the expression');
grid;

___________The End___________

Don’t look for someone who can solve your problems,


Instead go and stand in front of the mirror,
Look straight into your eyes,
And you will see the best person who can solve your problems!
Always trust yourself.

(BY ABU SULTAN)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy