MATLAB - Engineering Mathematics-I PDF
Document Details
Uploaded by Deleted User
PES University
null
Tags
Summary
This document provides an introduction to using MATLAB for engineering mathematics. It covers topics such as the introduction to MATLAB, MATLAB's power of computational mathematics, uses of MATLAB, and local environment setup. The document further details the MATLAB environment, hands-on practice, and more functions.
Full Transcript
ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Introduction to MATLAB MATLAB is a programming language developed by MathWorks. MATLAB stands for MATrix LABoratory. MATLAB is a program for doing numerical computation. It was originally designed for sol...
ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Introduction to MATLAB MATLAB is a programming language developed by MathWorks. MATLAB stands for MATrix LABoratory. MATLAB is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. While other programming languages mostly work with numbers one at a time, MATLAB is designed to operate primarily on whole matrices and arrays. Introduction to MATLAB, Continued… Using MATLAB, an image (or any other data like sound, etc.) can be converted to a matrix and then various operations can be performed on it to get the desired results and values. MATLAB is a fourth-generation high-level programming language and interactive environment for numerical computation, visualization and programming. It has numerous built-in commands and math functions that help in mathematical calculations, generating plots, and performing numerical methods. MATLAB's Power of Computational Mathematics MATLAB is used in every fact of computational mathematics. Following are some commonly used mathematical calculations where MATLAB is used: Dealing with Matrices and Arrays 2-D and 3-D Plotting and graphics Linear Algebra Algebraic Equations Statistics MATLAB's Power of Computational Mathematics, Continued… Data Analysis Calculus and Differential Equations Numerical Calculations Integration Transforms Curve Fitting Special Functions Uses of MATLAB MATLAB is widely used as a computational tool in Science and Engineering covering the fields of Physics, Chemistry, Mathematics, and all engineering streams. It is used in a range of applications including: Signal Processing and Communications Algorithm development Control Systems Computational Finance; Computational Biology Local Environment Setup Setting up MATLAB environment is a matter of few clicks. MathWorks provides the licensed product, a trial version, and a student version as well. We need to log into the site and wait a little for their approval. After downloading the installer, the software can be installed through few clicks. Local Environment Setup, Continued... Local Environment Setup, Continued... Understanding the MATLAB Environment Understanding the MATLAB Environment, Continued… The desktop has the following panels: Current Folder: This panel allows us to access the project folders and files. Understanding the MATLAB Environment, Continued… Command Window: This is the main area where commands can be entered at the command line. It is indicated by the command prompt (>>). Understanding the MATLAB Environment, Continued… Workspace: The workspace shows all the variables created and/or imported from files. Understanding the MATLAB Environment, Continued… Command History: This panel shows or return commands that are entered at the command line. MATLAB Screen Command Window type commands Current Directory View folders and m-files Workspace View program variables Double click on a variable to see it in the Array Editor Command History view past commands save a whole session using diary 15 Hands on Practice MATLAB environment behaves like a super-complex calculator. We can enter commands at the >> command prompt. In MATLAB, we give a command and it executes the command right away. Type a valid expression, for example, >>20 + 21; and press ENTER. When we click the Execute button, MATLAB executes it immediately and the result returned is ans=41. Hands on Practice, Continued… Let us take up few more examples: >>3 ^ 2 (%3 raised to the power of 2). When we click the Execute button, MATLAB executes it immediately and the result returned is ans=9. >>sin(pi/2). (% sine of angle 90). When we click the Execute button, MATLAB executes it immediately and the result returned is ans=1. >>7/0 (% Divide by zero). When we click the Execute button, MATLAB executes it immediately and the result returned is ans=Inf. Hands on Practice, Continued… >>732 * 20.3. When we click the Execute button, MATLAB executes it immediately and the result returned is ans=1.4860e+04. MATLAB provides some special expressions for some mathematical symbols, like pi for 𝜋, Inf for ∞, 𝑖 (and 𝑗) for −1. In MATLAB, NaN stands for 'not a number'. For example, >> 0/0; -inf/inf Use of Semicolon (;) in MATLAB Semicolon (;) indicates end of statement. However, if we want to suppress and hide the MATLAB output for an expression, add a semicolon after the expression. For example, >>x = 5; y = x + 5. When we click the Execute button, MATLAB executes it immediately and the result returned is y=8. Adding Comments in MATLAB To add comments to MATLAB code, we use the percent ( % ) symbol. Comment lines can appear anywhere in a program file, and we can add comments to the end of a line of code. For example, y = sum(x) % Use the sum function Commonly used Operators and Special Characters Operation Symbol Example Addition + 5+3=8 Subtraction - 5-3=2 Multiplication * 5*3=15 Right Division / 5/3=1.6667 Left Division \ 5/3=3\5=1.667 Exponentiation ^ 5^3=125 Special Variables and Constants MATLAB supports the following special variables and constants: Naming Variables Variable names consist of a letter followed by any number of letters, digits or underscore. MATLAB is case-sensitive. For example, >>x = 10 (% defining x and initializing it with a value). MATLAB will execute the above statement and return the following result x = 10. >>x = sqrt(25) (% defining x and initializing it with an expression) MATLAB will execute the above statement and return the result as x = 5. Naming Variables, Continued… Note that once a variable is entered into the system, we can refer to it later. Variables must have values before they are used. When an expression returns a result that is not assigned to any variable, the system assigns it to a variable named answer, which can be used later. For example, >>x = 7 * 8; y = x * 7.89. MATLAB will execute the above statement and return the following result y = 441.8400. Multiple assignments We can have multiple assignments on the same line. For example, >> a = 2; b = 7; c = a * b MATLAB will execute the above statement and return the result c = 14. I have forgotten the Variables The who command displays all the variable names we have used. MATLAB will execute the above statement and return the result: Your variables are: ans - - - … The whos command. MATLAB will execute the above statement and return the following result. I have forgotten the Variables >> clear x. It will delete x, won't display anything. >> clear. It will delete all variables in the workspace. >> clc. It clears all the text from the Command Window, resulting in a clear screen. Long Assignments Long assignments can be extended to another line as follows: >> initial_velocity = 0; >> acceleration = 9.8; >> time = 20; >> Final_velocity = initial_velocity + acceleration * time MATLAB will execute the above statement and return the following result: final velocity = 196. The format Command By default, MATLAB displays numbers with four decimal place values. This is known as short format. However, if we want more precision, then we need to use the format command. The format long command displays 15 digits after the decimal point. For example: >> format long >> x = 7 + 10/3 + 5 ^ 1.2 MATLAB will execute the above statement and return the following result: x = 17.231981640639408. The format Command, Continued… Another example, >> format short >> x = 7 + 10/3 + 5 ^ 1.2 MATLAB will execute the above statement and return the following result: x = 17.232 The format bank command rounds numbers to two decimal places. The format Command, Continued… For example, >> format bank >> daily_wage = 177.45; weekly_wage = daily_wage * 6 MATLAB will execute the above statement and return the following result: weekly_wage = 1064.70 MATLAB displays large numbers using exponential notation. The format short e command allows displaying in exponential form with four decimal places plus the exponent. The format Command, Continued… For example, >> format short e >> 4.678 * 4.9 MATLAB will execute the above statement and return the following result: ans = 2.2922e+01 The format long e command allows displaying in exponential form with fifteen decimal places plus the exponent. The format Command, Continued… For example, >> format long e >> x = pi MATLAB will execute the above statement and return the following result: x = 3.141592653589793e+00 The format rat command gives the closest rational expression resulting from a calculation. For example, >> format rat >> 4.678 * 4.9 MATLAB will execute the above statement and return the following result: ans = 34177/1491 Creating Vectors A vector is a one-dimensional array of numbers. MATLAB allows creating two types of vectors: Row vectors and Column vectors. Row vectors are created by enclosing the set of elements in square brackets, using space or comma. For example, >> X = [7 8 9 10 11]. MATLAB will execute the above statement and return the following result: X= 7 8 9 10 11 Creating Vectors, Continued… Another example, >> X = [7 8 9 10 11]; >> Y = [2, 3, 4, 5, 6]; >> Z = X +Y MATLAB will execute the above statement and return the following result: Z= 9 11 13 15 17 Creating Vectors, Continued… Column vectors are created by enclosing the set of elements in square brackets, using semicolon(;). For example, >> X = [7; 8; 9; 10] MATLAB will execute the above statement and return the following result: X= 7 8 9 10 Creating matrices A matrix is a two-dimensional array of numbers. In MATLAB, a matrix is created by entering each row as a sequence of space or comma separated elements, and end of a row is terminated by a semicolon. For example, let us create a 3-by-3 matrix as >>A = [1 2 3 4; 4 5 6 7; 7 8 9 10] Creating matrices, Continued… MATLAB will execute the above statement and return the following result: A= 1 2 3 4 4 5 6 7 7 8 9 10 Elementary Math Built – In Functions Function Description Examples sqrt(x) Square root >>sqrt(81) ans=9 nthroot(x,n) Real nth root of a real number x. (If x is negative n >>nthroot(8,3) must be an odd integer). ans=2 exp(x) Exponential(e^x) >>exp(5) ans=1.484131591025766e+02 abs(x) Absolute value >>abs(-24) ans=24 log(x) Natural logarithm. Base e logarithm (ln) >>log(1000) ans=6.907755278982137e+00 log10(x) Base 10 logarithm >>log10(1000) ans=3 factorial(x) The factorial function x! >>factorial(5) (x must be a psitive integer) ans=120 Trigonometric Math Functions Function Description Examples sin(x) Sine of angle x ( x in radians) >>sin(pi/6) ans=0.5000 sind(x) Sine of angle x (x in degrees) >>sind(30) ans=0.5000 cos(x) Cosine of angle x (x in radians) >>cos(0.5) ans=0.8776 cosd(x) Cosine of angle x (x in degrees) >>cosd(30) ans=0.8660 tan(x) Tangent of angle x (x in radians) >>tan(pi/6) ans=0.5774 tand(x) Tangent of angle x (x in degrees) >>tand(45) ans=1 cotx) Cotangent of angle x (x in radians) >>cot(0.5) ans=1.8305 cotd(x) Cotangent of angle x ( x in degrees) >>cotd(90) ans=1 asin(x) Inverse of sine of angle x (x in radians) >>asin(0.5) ans=0.5236 asind(x) Inverse of sine angle x ( x in degrees) >>asin(0.8660) ans=59.9971 acos(x) Inverse of cosine of angle x (x in radians) >>acos(0.3) ans=1.2661 acosd(x) Inverse of cosine angle x ( x in degrees) >>acosd(0.5) ans=60 Rounding Functions Function Description Examples round(x) Round to the nearest integer >>round(25/3) ans=8 >>round(4.49) ans=4 >>round(4.5) ans=5 >>round(4.9999) ans=5 fix(x) Round towards zero. In other words, chops off the >>fix(17/5) ans=3 fraction part. >>fix(4.49) ans=4 >>fix(4.9999) ans=4 >>fix(-4.6674) ans=-4 ceil(x) Round towards positive infinity. >>ceil(27/2) ans=14 >>ceil(2.1) ans=3 >>ceil(2.9) ans=3 >>ceil(-4.99) ans=-4 floor(x) Round towards minus infinity >>floor(-9/4) ans=-3 >>floor(2.1) ans=2 >>floor(2.99) ans=2 rem(x,y) Returns the remainder after x is divided by y >>rem(13,5) ans=3 Examples for Arithmetic operators 1) Calculate the following using MATLAB. 1 4 6 2 + ∗ 2+3 5 7 >>a=1/(2+3^2) a= 0.0909 >>b=4/5 b= 0.8000 >>c=6/7 c= 0.8571 >>a+b*c ans= 0.7766 2. Find the value of 𝑦 = 𝑒 −𝑎 sin x + 10 𝑦 𝑖𝑓 𝑎 = 5, 𝑥 = 2, 𝑦 = 8. >>a=5; x=2; y=8; y=exp(-a)*sin(x)+10*sqrt(y) y= 2.829039804533026e+013. 𝜋 3. Compute sin , 𝑒10. 4 >>sin(pi/4) ans=0.7071 >>exp(10) ans=2.2026e+004 Reference: 1. Getting started with MATLAB, Rudra Pratap, Oxford University Press, 7th Edition, 2016. 2. https://www.tutorialspoint.com/matlab/matlab_data_import. htm THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Data Types Data types are those which define the type of data that we are using. Every data type stores data that is in the form of a matrix or array. Some common data types are: Integers Floating point numbers Scalar Character Strings Arrays Integers An integer is a whole number (not a fraction) that can be positive, negative, or zero. For example, the numbers 10, 0, and -25 are integers. When two integers are added, subtracted, or multiplied, the result is also an integer. Integers, Continued… For example: >> 2+3 ans = 5 >> 4-5 ans = -1 Integers, Continued… >> 2*8 ans = 16 Note that when one integer is divided by another integer, the result may be an integer or a fraction. For example: >> 6/4 ans = 3/2 Integers, Continued… >> 6/3 ans = 2 Floating Point Numbers As the name indicates, floating point numbers are numbers that contain floating decimal points. For example, the numbers 6.5, 0.0001, and -2,345.6789 are floating point numbers. When a calculation includes a floating point number, it is called a "floating point calculation." Scalar Any number which is used to represent a quantity. This includes integers, complex numbers , floating point numbers. Examples of scalar data types are: 3, 4+6i, -20.45. Character Single alphanumeric symbol enclosed in a single quote is a character constant. Example, ‘B’ and ‘6’. 6 and ‘6’ are different. Here, 6 is numeric constant and ‘6’ is character constant. Strings Any two or more alphanumeric symbols enclosed in a single quote. Example, ‘INDIA’=[‘I’, ‘N’, ‘D’, ‘I’, ‘A’] Arrays List of similar data in a single row or a column. Elements can be numerical or character or strings. Examples, [1 2 3 4]; [a b c d]. Special Types of Arrays The four types of arrays are: zeros() function eye() function ones() function. rand() function Special Types of Arrays, Continued… Zeros() Function : It creates an array of all zeros. For example: >> zeros(5) MATLAB will execute the above statement and return the result: ans =. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Special Types of Arrays, Continued… eye() function: It creates an identity matrix. For example: >> eye(4) MATLAB will execute the above statement and return the result: ans =. 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 Special Types of Arrays, Continued… ones() function: It creates an array of all ones. For example: >> ones(4,3) MATLAB will execute the above statement and return the result: ans =. 1 1 1 1 1 1 1 1 1 1 1 1 Special Types of Arrays, Continued… rand() function: It generates random numbers between 0 and 1 that are distributed uniformly. For example: >> rand(3, 5) MATLAB will execute. the above statement and return the result ans = 0.8147 0.9134 0.2785 0.9649 0.9572 0.9058 0.6324 0.5469 0.1576 0.4854 0.1270 0.0975 0.9575 0.9706 0.8003 Relational Operators: Relational operator compare the elements in two arrays and return logical true or false values to indicate where the relation holds. == Determine the equality >= Determine greater than or equal to. > Determine greater than > 10==20 2. >> 3==(45-42) 3. >> x=(16*64>1000)+9 4. >> [4 -1 7 5 3]> sum([14 9 3 4 1 4]==4) 6. >> x=10; x~=20 7. >> 3~=4 8. >>3~=3 Logical Operators: The logical data type represents true or false states using the numbers 1 and 0, respectively. The three logical operators are &; |; and ~ The meaning of & operator is AND. The meaning of | operator is OR The meaning of ~ operator is NOT Logical Operator & truth table: Logical operator AND (&): It is true (1), when both the operands are true (1), otherwise the result is false (0). operand operand AND operand. 1 1 1 1 0 0 0 1 0 0 0 0 Logical Operator &, Continued… For example, >> a=[1 1 1 0 0 0]; >> b=[0 0 0 1 1 1]; >> a&b. ans = 1×6 logical array 0 0 0 0 0 0 Logical Operator &, Continued… Consider, >> a=1; b=1; >> a&b ans =. logical 1 Logical Operator &, Continued… Consider, >> a=0; b=1; >> a&b ans = logical. 0 Logical Operator |, truth table: Logical operator OR (|): It is true (1), when one or both the operands are true (1), otherwise the result is false (0). operand operand operand OR operand 1 1 1. 1 0 1 0 1 1 0 0 0 Logical Operator |, Continued… Consider, >>a=[1 1 1 0 0 0]; b=[0 0 0 1 1 1]; >> a|b ans =. 1×6 logical array 1 1 1 1 1 1 Logical Operator ~ truth table: operand NOT operand 1 0 0. 1 Logical Operator ~, Continued… For example, consider , >>[1 pi 0 -2] ans =. 1.0000 3.1416 0 -2.0000 >> ~[1 pi 0 -2] ans = 1×4 logical array 0 0 1 0 THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities The M-Files: In MATLAB, we write programs in M-files. They are called M-files because they have a.m at the end of their name, (for example: myfunction.m). M-files are ordinary ASCII text files written in MATLAB’s Language. M-files can be created using any editor or word processing applications. There are two types of M-files: Script files and Function files. Script Files: Creating and Running Script Files A script file is an M-file with a set of valid MATLAB commands in it. To create scripts files, we need to use a text editor. We can open the MATLAB editor using the command prompt. If we use the command prompt, then we type edit and then the filename (with.m extension). This will open the editor. The above command will create the file in default MATLAB directory. Alternatively, we can choose NEW -> Script. This also opens the editor and creates a file named untitled. We can name and save the file after typing the code. Script Files; Creating and Running Script Files A script file is an M-file with a set of valid MATLAB commands in it. To open the script file, choose NEW -> Script. This opens the editor and creates a file named untitled. We can name and save the file after typing the code. Creating and Running Script Files, Continued… Consider an example: Type the following code in the editor: >> a=25; b=26; c=27; d=a+b+c After creating and saving the file, you can run it by clicking the Run button on the editor window. The command window prompt displays the result: d=78 Function Files A function is a group of statements that together perform a task. In MATLAB, functions are defined in separate files. Functions can accept more than one input arguments and may return more than one output arguments. Function Files The syntax of the function definition line is as follows: function [output variables] = function_name(input variables) Note that the function_name must be the same as the file name (without the.m extension) in which the function is written. Function Files, Continued… Consider the following example: First, create a script file as myname.m for the following: >> a=20; b=21; c=22; sum=a+b+c (Press Run icon) prod=a*b*c (Press Run icon) Then the following result is displayed on the command window: sum = 63; prod =9240. Function Files, Continued… Create a function file: >> function [sum,prod] = myname(a,b,c) sum = a+b+c; prod=a*b*c; end On command window, type the following: For, >> myname(20,21,22), the output is: ans =63 For, >> [s,p]=myname(20,21,22), the output is: s = 63, p =9240 THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities MATLAB – Plotting To plot the graph of a function, we need to take the following steps: Define x, by specifying the range of values for the variable x, for which the function is to be plotted. Define the function, y = f(x). Call the plot command, as plot(x, y). The plot command is used to create two-dimensional plots. Following example would demonstrate the concept. Let us plot the function 𝑦 = 3.5−0.5𝑥 cos 6𝑥 for −2 ≤ 𝑥 ≤ 4. MATLAB – Plotting, Continued… The script file is as follows: >> x=[-2:0.01:4]; (Here 0.01 is the spacing value) >> y=3.5.^(-0.5*x).*cos(6*x); >> plot(x,y) Here 𝑦 is plotted as a function of 𝑥. MATLAB – Plotting, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Plotting, Continued… Let us take another example to plot the function 𝑦 = 𝑥 2. In this example, we will draw two graphs with the same function, but in second time, we will reduce the value of increment. Note that as we decrease the increment, the graph becomes smoother. The script file is as follows: >> x = [-100:20:100]; >> y = x.^2; >> plot(x, y) MATLAB – Plotting, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Plotting, Continued… Change the code file a little, reduce the increment to 5. >> x = [-100:5:100]; >> y = x.^2; >> plot(x, y). When you run the file, MATLAB displays the following plot: MATLAB - Three Dimensional Plots Three-dimensional plots display a surface defined by a function in two variables, 𝑔 = 𝑓(𝑥, 𝑦). To define the function 𝑔 = 𝑓(𝑥, 𝑦), we first create a set of 𝑥, 𝑦 points over the domain of the function using the meshgrid command. Next, we assign the function itself. Finally, we use the surf command to create a surface plot. MATLAB - Three Dimensional Plots, Continued… The following example demonstrates the concept: − 𝑥 2 +𝑦 2 Let us create a 3D surface map for the function 𝑧 = 𝑥𝑒 The script file is as follows: >> [x,y] = meshgrid(-2:.2:2); >> z = x.* exp(-x.^2 - y.^2); >> surf(x,y,z) MATLAB - Three Dimensional Plots, Continued… When we run the file, MATLAB displays the following 3-D map: MATLAB - Three Dimensional Plots, Continued… Let us consider another example to create a 3D surface map for the function 𝑧 = sinx + cosy The script file is as follows: >> [x,y] = meshgrid(-2:.2:2); >> z=sin(x)+cos(y); >> surf(x,y,z) MATLAB - Three Dimensional Plots, Continued… When we run the file, MATLAB displays the following 3-D map: MATLAB - Three Dimensional Plots, Continued… Let us consider another example to create a 3D surface map for 𝑥𝑦 𝑥 2 −𝑦 2 the function 𝑧 =. 𝑥 2 +𝑦 2 The script file is as follows: >> [x,y] = meshgrid(-2:.2:2); >> z=x.*y.*(x.^2-y.^2)./(x.^2+y.^2); >> surf(x,y,z) MATLAB - Three Dimensional Plots, Continued… When we run the file, MATLAB displays the following 3-D map: Adding Title and Labels on the Graph Using MATLAB we can add title, labels along the x-axis and y-axis of the graph. The xlabel and ylabel commands generate labels along x-axis and y-axis. The title command allows you to put a title on the graph. The script file is as follows: >> x = [0:0.01:10]; >> y = sin(x); >> plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph') Adding Title and Labels on the Graph When we run the file, MATLAB displays the following plot: MATLAB – Polar Plots To plot a curve in polar coordinates, we use the following command: polarplot(theta,rho). Here theta is the angle in radians and rho is the radius value for each point. Following example would demonstrate the concept. Let us plot the curve 𝑟 = 𝑠𝑖𝑛2𝜃𝑐𝑜𝑠2𝜃. MATLAB – Polar Plots, Continued… The script file is as follows: >> theta = 0:0.01:2*pi; >> rho = sin(2*theta).*cos(2*theta); >> polarplot(theta,rho) MATLAB – Polar Plots, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Polar Plots, Continued… Consider another example: Plot the curve 𝑟 = 1 − 𝑠𝑖𝑛𝜃 The script file is as follows: >> theta = 0:0.01:2*pi; >> rho = 1 - sin(theta); >> polar(theta, rho) MATLAB – Polar Plots, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Polar Plots, Continued… Consider another example: Plot the curve 𝑟 = 𝑐𝑜𝑠2𝜃 The script file is as follows: >> theta = 0:0.01:2*pi; >> rho = cos(2*theta); >> polar(theta, rho) MATLAB – Polar Plots, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Parametric Plots To plot a parametric curve, we use the following command: fplot3(xt,yt,zt), which plots the parametric curve xt=x(t), yt=y(t), and zt=z(t) over the default interval −5 < 𝑡 < 5. Following example would demonstrate the concept. Let us plot a parametric curve: x=sin(t); y=cos(t); z=t over the default parameter range [-5 5]. MATLAB – Parametric Plots, Continued… The script file as follows: >> syms t >> xt = sin(t); >> yt = cos(t); >> zt = t; >> fplot3(xt,yt,zt) MATLAB – Parametric Plots, Continued… When we run the file, MATLAB displays the following plot: MATLAB – Polar Plots, Continued… Consider another example: Plot the parametric curve 𝑡 𝑡 −10 −10 𝑥=𝑒 sin 5𝑡 ; 𝑦 = 𝑒 cos 5𝑡 ; 𝑧 = 𝑡 over the parameter range [-10 10] Note that fplot3(xt,yt,zt, [tmin tmax]) plots xt = x(t), yt = y(t), and zt = z(t) over the interval tmin < t < tmax. MATLAB – Parametric Plots, Continued… The script file as follows: >> syms t >> xt = exp(-t/10).*sin(5*t); >> yt = exp(-t/10).*cos(5*t); >> zt = t; >> fplot3(xt,yt,zt,[-10 10]) MATLAB – Parametric Plots, Continued… When we run the file, MATLAB displays the following plot: THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Finding partial derivative of a function: Find the first order partial derivatives of i) 𝑢 = 𝑥 2 y + 𝑦 2 𝑧 + 𝑧 2 𝑥 ii) 𝑧 = sin(2𝑥 + 3𝑦) 𝑖𝑖𝑖) 𝑢 = 𝑥 2 + 𝑦 2 + 𝑧 2 + 𝑡𝑎𝑛−1 ( 𝑥𝑦) Finding partial derivative of a function, Continued… Find the first order partial derivatives of i) 𝑢 = 𝑥 2 y + 𝑦 2 𝑧 + 𝑧 2 𝑥 syms x y z u=x^2*y+y^2*z+z^2*x; diff(u,x) diff(u,y) diff(u,z) Finding partial derivative of a function, Continued… Find the first order partial derivatives of ii) 𝑧 = sin(2𝑥 + 3𝑦) syms x y u=sin(2*x+3*y); diff(u,x) diff(u,y) Finding partial derivative of a function, Continued… Find the first order partial derivatives of iii) 𝑢 = 𝑥 2 + 𝑦 2 + 𝑧 2 + 𝑡𝑎𝑛−1 ( 𝑥𝑦) syms x y z u=sqrt(x^2+y^2+z^2)+atan(x*y); diff(u,x) diff(u,y) diff(u,z) Finding partial derivative of a function, Continued… 2 Find all the second order partial derivatives of 1 1 𝑓 𝑥, 𝑦 = 𝑙𝑜𝑔 − at (1,2). 𝑥 𝑦 syms x y f=log((1/x)-(1/y)); F=diff(f,x,2) subs(F,[x,y],[1,2]) G=diff(f,y,2) subs(G,[x,y],[1,2]) Finding partial derivative of a function, Continued… H=diff(f,x,y) subs(H,[x,y],[1,2]) I=diff(f,y,x) subs(I,[x,y],[1,2]) Finding partial derivative of a function, Continued… 3 If 𝑢 = 𝑒 𝑥𝑦+𝑦𝑧+𝑧𝑥 , then find 𝑢𝑥𝑦 , 𝑢𝑦𝑧 and 𝑢𝑧𝑥. syms x y z u=exp(x*y+y*z+z*x); diff(u,x,y) diff(u,y,z) diff(u,z,x) Finding partial derivative of a function, Continued… 4 𝑥𝑦𝑧 𝜕3 𝑢 𝜕3 𝑢 𝜕3 𝑢 If 𝑢 = 𝑒 , then find , and 𝜕𝑥𝜕𝑦𝜕𝑧 𝜕𝑥 2 𝜕𝑧 𝜕𝑦 2 𝜕𝑧 syms x y z u=exp(x*y*z); diff(u,x,y,z) diff(u,x,x,z) diff(u,y,y,z) Finding partial derivative of a function, Continued… 𝜕2 𝑓 𝜕2 𝑓 5. Show that = for all 𝑥 > 0, 𝑦 > 0 when 𝜕𝑥𝜕𝑦 𝜕𝑦𝜕𝑥 𝑓 𝑥, 𝑦 = 𝑥 𝑦 + 𝑦 𝑥 syms x y u=x^y+y^x; diff(u,x,y) diff(u,y,x) Finding partial derivative of a function: Find the partial derivative of the following functions: a) If f = sin 𝑥 + 𝑦 3 + 𝑥 10 − 𝑦 2 + log 𝑥 , then find 𝑓𝑥 & 𝑓𝑦. b) If f = 𝑥 2 + 2 ∗ 𝑦 2 − 22, then find 𝑓𝑥 2 & 𝑓𝑦 2. c) If f = 𝑥𝑦 3 + 𝑡𝑎𝑛𝑥 + 𝑐𝑜𝑠 𝑙𝑜𝑔𝑥, then find 𝑓𝑥. xy3 d) If f = ൗx+y , then find fx ; fy ; fx 2 ; fx𝑦 ; fyx. Finding partial derivative of a function, Continued… If f = sin 𝑥 + 𝑦 3 + 𝑥 10 − 𝑦 2 + log 𝑥 , then find 𝑓𝑥 & 𝑓𝑦. syms x y f=sin(x)+y^3+x^10-y^2+log(x); diff(f,x) diff(f,y) Out put: f =log(x) + sin(x) + x^10 - y^2 + y^3 ans =cos(x) + 1/x + 10*x^9 ans =3*y^2 - 2*y Finding partial derivative of a function, Continued… If f = 𝑥 2 + 2 ∗ 𝑦 2 − 22, then find 𝑓𝑥𝑥 & 𝑓𝑦𝑦. syms x y f=x^2+2*y^2-22 diff(f,x,2) diff(f,y,2) Out put: f = x^2 + 2*y^2 – 22 ans =2 ans=4 Finding partial derivative of a function, Continued… If f = 𝑥𝑦 3 + 𝑡𝑎𝑛𝑥 + 𝑐𝑜𝑠 𝑙𝑜𝑔𝑥, then find 𝑓𝑥. syms x y; f=x*y^3+tan(x)+cos(sqrt(log(x))) diff(f,x) Out put: f = cos(log(x)^(1/2)) + tan(x) + x*y^3 ans =tan(x)^2 + y^3 - sin(log(x)^(1/2))/(2*x*log(x)^(1/2)) + 1 Finding partial derivative of a function, Continued… 𝑥𝑦 3 If f = , then find fx ; fy ; fx 2 ; fx𝑦 ; fyx. 𝑥+𝑦 syms x y f=(x*y^3)/(x+y) diff(f,x) diff(f,y) diff(f,x,2) diff(f, x, y) diff(f, y, x) Finding partial derivative of a function, Continued… Out put: f = (x*y^3)/(x + y); ans = y^3/(x + y) - (x*y^3)/(x + y)^2 ans =(3*x*y^2)/(x + y) - (x*y^3)/(x + y)^2 ans =(2*x*y^3)/(x + y)^3 - (2*y^3)/(x + y)^2 ans = (3*y^2)/(x + y) - y^3/(x + y)^2 - (3*x*y^2)/(x + y)^2 + (2*x*y^3)/(x + y)^3 ans = (3*y^2)/(x + y) - y^3/(x + y)^2 - (3*x*y^2)/(x + y)^2 + (2*x*y^3)/(x + y)^3 Note that fx𝑦 = fyx. Taylor’s and Maclaurin’s series expansion of a function of single variable: 1. Expand f(x)=𝑒 𝑥𝑠𝑖𝑛𝑥 about the point x = 2 up to third degree terms. >> syms x >> f = exp(x*sin(x)); >> t= taylor(f, 'ExpansionPoint', 2, 'Order', 3) Out put: t=exp(2*sin(2)) + exp(2*sin(2))*(2*cos(2) + sin(2))*(x - 2) + exp(2*sin(2))*(x - 2)^2*(cos(2) - sin(2) + (2*cos(2) + sin(2))*(cos(2) + sin(2)/2)) Taylor’s and Maclaurin’s series expansion of a function of single variable: 𝜋 2. Expand f(x)=log(cosx) about the point x = up to fifth 3 degree terms. >> syms x >> f = log(cos(x)); >> t= taylor(f, 'ExpansionPoint', pi/3, 'Order', 5) Out put: t = - log(2) - 3^(1/2)*(x - pi/3) - (4*3^(1/2)*(x - pi/3)^3)/3 - 2*(x - pi/3)^2 - (10*(x - pi/3)^4)/3 Taylor’s and Maclaurin’s series expansion of a function of single variable: 3. Expand f(x)=log(secx) about the origin up to seven degree terms. syms x f = log(sec(x)); T= taylor(f, 'Order', 7) Out put: T = x^6/45 + x^4/12 + x^2/2 Taylor’s and Maclaurin’s series expansion of a function of single variable: 4. Expand f(x)=sin(log(x^2+2x+1)) about the origin up to seven degree terms. >> syms x >> f = sin(log(x^2+2*x+1)); >> T= taylor(f, 'Order', 7) Out put: T= (3*x^6)/2 - (5*x^5)/3 + (3*x^4)/2 - (2*x^3)/3 - x^2 + 2*x Taylor’s and Macluarin’s series expansion of a function of single variable: (i) Expand f x = ex in Taylor’s series up to fifth degree terms about the origin. (ii) Expand f x = cosx in Taylor’s series up to third order terms about the origin. Taylor’s and Macluarin’s series expansion of a function of two variables: x 𝜋 1. Expand f x, y = e 𝑐𝑜𝑠𝑦 about the point 𝑥 = 1, 𝑦 = 4 up to three degree terms. >> syms xy >> f=exp(x)*cos(y); >> t = taylor(f, [x, y], [1, pi/4], 'Order', 3) Taylor’s and Macluarin’s series expansion of a function of two variables: Out put: T = (2^(1/2)*exp(1))/2 - (2^(1/2)*exp(1)*(y - pi/4)^2)/4 + (2^(1/2)*exp(1)*(x - 1)^2)/4 - (2^(1/2)*exp(1)*(y - pi/4))/2 + (2^(1/2)*exp(1)*(x - 1))/2 - (2^(1/2)*exp(1)*(y - pi/4)*(x - 1))/2 Taylor’s and Macluarin’s series expansion of a function of two variables: 2. Expand f x, y = 𝑥 3 + 𝑦 3 + 𝑥𝑦 2 about 𝑥 = 1, 𝑦 = 2 up to fourth degree terms. >> syms x y >> f=x^3+y^3+x*y^2; >> t = taylor(f, [x, y], [1, 2], 'Order', 4) Out put: t=7*x + 16*y + 4*(x - 1)*(y - 2) + 3*(x - 1)^2 + (x - 1)^3 + 7*(y - 2)^2 + (y - 2)^3 + (x - 1)*(y - 2)^2 - 26 Taylor’s and Macluarin’s series expansion of a function of two variables: 3. Expand 𝑓 𝑥, 𝑦 = 𝑒 𝑦 log(1 + 𝑥) about the origin up to fourth degree terms. >> syms x y >> f=exp(y)*log(1+x); >> T= taylor(f, [x, y], 'Order', 4) Out put: T= x^3/3 - (x^2*y)/2 - x^2/2 + (x*y^2)/2 + x*y + x Taylor’s and Macluarin’s series expansion of a function of two variables: 4. Expand 𝑓 𝑥, 𝑦 = 𝑒 𝑥 tany about the origin up to fifth degree terms. >> syms x y >> f=exp(x)*tan(y); >> T= taylor(f, [x, y], 'Order', 5) Out put: T =(x^3*y)/6 + (x^2*y)/2 + (x*y^3)/3 + x*y + y^3/3 + y Taylor’s and Macluarin’s series expansion of a function of single variable: −1 𝑦 (i) Expand 𝑓 𝑥, 𝑦 = 𝑡𝑎𝑛 in Taylor’s series up to second 𝑥 order terms about the point 1,1 (ii) Expand f x, 𝑦 = sin(𝑥 + 2𝑦) in Taylor’s series up to third order terms about the point 0,0 (iii) Expand f x, 𝑦 = sinx𝑠𝑖𝑛𝑦 in Taylor’s series up to second 𝜋 𝜋 order terms about the point ,. 4 4 THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Solution of first order differential equations We can solve a differential equation analytically by using the dsolve function, with or without initial conditions: 1. First-Order Linear ODE. 2. First-Order Linear ODE with Initial Condition. 3. Nonlinear Differential Equation with Initial Condition. Solution of first order differential equations, Continued… 𝑑𝑦 Solve the differential equation: 𝑑𝑥 = 𝑥𝑦 % First, represent y by using syms to create the symbolic function y(x) >> syms y(x) % Define the equation using == and represent differentiation using the diff function: >> ode = diff(y,x) == x*y; % Solve the equation using dsolve: >> ySol(x) = dsolve(ode) Output: ySol(x) =C1*exp(x^2/2) Solution of first order differential equations, Continued… 𝑑𝑥 Solve the differential equation: 𝑑𝑡 = 𝑥 + 𝑡, given 𝑥 0 = 0. >> syms x(t) >> ode = diff(x,t) == x+t; >> xSol(t) = dsolve(ode) Output: xSol(t) =C1*exp(t) - t – 1. To find the value of C1, we use: >> cond = x(0) == 0; >> xSol(t) = dsolve(ode,cond) Output: ySol(t) =exp(t) - t - 1 Plot the graph of solution of first order differential equations 𝑑𝑥 Plot the solution of the differential equation: = 𝑥 + 𝑡, given 𝑑𝑡 𝑥 0 = 0. >> tspan=[0 2]; % specify time span >> x0=0; % specify x0 >> [t,x]=ode45(@(t,x)x+t,tspan,x0); % now execute ode45 >> disp([t,x]) Here 𝑡 is a vector containing all discrete points of time at which the solution was obtained; and 𝑥 contains the values of the variable 𝑥 at those instances of time. Let us plot the solution graphically: >> plot(t,x) % plot t verses x Plot the graph of solution of first order differential equations, Continued The graph looks like: Plot the graph of solution of first order differential equations, Continued 𝒅𝒚 𝒙𝟑 +𝒚𝟑 Plot the solution of the differential equation: = , given 𝒅𝒙 𝒚𝟐 𝑦 0 = 2. >> xspan=[0 3]; >> y0=2; >> [x,y]=ode45(@(x,y)(x^3+y^3)/(y^2),xspan,y0); >> disp([x,y]) >> plot(x,y) Plot the graph of solution of first order differential equations, Continued The graph looks like: Plot the graph of solution of first order differential equations, Continued 2 𝑑𝑦 Plot the solution of the differential equation: 𝑥 − 1 + 2𝑥𝑦 = 1, 𝑑𝑥 given 𝑦 0 = 1. >> y0=1; >> x0=0; >> xend=[1,5,10]; >> xspan=[x0,xend]; >> [x,y]=ode45(@(x,y)(1-2*x*y)/(x^2-1),xspan,y0); >> disp([x,y]) >> plot(x,y) Plot the graph of solution of first order differential equations, Continued The graph looks like: Plot the graph of solution of first order differential equations, Continued 𝑑𝑦 Plot the solution of the differential equation: 𝑑𝑡 = 3𝑡, given 𝑦 0 = 1. Find y(1),y(5), and y(10). >> y0=1; >> t0=0; >> tend=[1,5,10]; >> tspan=[t0,tend]; >> [t,y]=ode45(@(t,y)3*t,tspan,y0); >> disp([t,y]) >> plot(t,y) Solution of first order differential equations, Continued… 𝑑𝑦 2 Solve the nonlinear differential equation: +𝑦 = 1, given 𝑦 0 = 0. 𝑑𝑡 Plot the solution graphically. >> syms y(t) >> ode = (diff(y,t)+y)^2 == 1; >> ySol(t) = dsolve(ode) Output: ySol(t) = C1*exp(-t) + 1; C2*exp(-t) – 1 To find the values of C1 and C2, we use: >> cond = y(0) == 0; >> ySol(t) = dsolve(ode,cond) Output: ySol(t) =exp(-t) – 1; 1 - exp(-t) THANK YOU ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Higher order differential equations: Solve: 𝑦 ′′ + 9𝑦 = 0. >> syms y(x) >> ode = diff(y,x,2)+9*y == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C1*cos(3*x) - C2*sin(3*x) Higher order differential equations, Continued… Solve: 2𝑦 ′′ + 3𝑦 ′ − 2𝑦 = 0. >> syms y(x) >> ode = 2*diff(y,x,2)+3*diff(y,x,1)-2*y == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C1*exp(-2*x) + C2*exp(x/2) Higher order differential equations, Continued… Solve: 𝑦 ′′ − 3𝑦 ′ + 2𝑦 = 0, y 0 = −1, 𝑦 ′ 0 = 0. >> syms y(x) >> Dy = diff(y); >> D2y = diff(y,2); >> ode = D2y - 3*Dy + 2*y == 0; >> ySol = dsolve(ode, y(0) == -1, Dy(0) == 0) % Define The Initial >> Condition For ‘Dy(0)’ To Be ‘Some Value’ >> figure >> ezplot(ySol) Higher order differential equations, Continued… Output: ySol = exp(2*x) - 2*exp(x) Higher order differential equations, Continued… Solve: 4𝑦 ′′′ + 4𝑦 ′′ + 𝑦 ′ = 0. >> syms y(x) >> ode = 4*diff(y,x,3)+4*diff(y,x,2)+diff(y,x,1) == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C1 + C2*exp(-x/2) + C3*x*exp(-x/2) Higher order differential equations, Continued… Solve: 𝑦 ′′′ − 4𝑦 ′′ + 𝑦 ′ + 6𝑦 = 0. >> syms y(x) >> ode = diff(y,x,3)-4*diff(y,x,2)+diff(y,x,1)+6*y == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C1*exp(-x) + C2*exp(2*x) + C3*exp(3*x) Higher order differential equations, Continued… Solve: 𝑦 ′′′ − 6𝑦 ′′ + 11𝑦 ′ − 6𝑦 = 0, 𝑦 0 = 0, 𝑦 ′ 0 = 0, 𝑦 ′′ 0 = 2. >> syms y(x) >> Dy = diff(y); >> D2y = diff(y,2); >> D3y = diff(y,3); >> ode = D3y - 6*D2y + 11*Dy - 6*y == 0; >> ySol = dsolve(ode, y(0) == 0, Dy(0) == 0,D2y(0) == 2 ) % Define The Initial Condition For ‘Dy(0)’,'D2y(0)' To Be ‘Some Values’. Higher order differential equations, Continued… >> figure >> ezplot(ySol) Output: ySol =exp(3*x) - 2*exp(2*x) + exp(x) Higher order differential equations, Continued… Solve: 𝑦 ′′′′ = 0. >> syms y(x) >> ode = diff(y,x,4) == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =(C1*x^3)/6 + (C2*x^2)/2 + C3*x + C4 Higher order differential equations, Continued… 𝑑4 𝑦 𝑑2 𝑦 Solve: +8 2 + 16𝑦 = 0. 𝑑𝑥 4 𝑑𝑥 >> syms y(x) >> ode = diff(y,x,4)+8*diff(y,x,2)+16*y == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C1*cos(2*x) - C3*sin(2*x) + C2*x*cos(2*x) - C4*x*sin(2*x) Higher order differential equations, Continued… 𝑑4 𝑦 Solve: + 4𝑦 = 0. 𝑑𝑥 4 >> syms y(x) >> ode = diff(y,x,4)+4*y == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) = C3*exp(x)*cos(x) - C4*exp(x)*sin(x) + C1*exp(-x)*cos(x) - C2*exp(-x)*sin(x) Higher order differential equations, Continued… Solve: 𝑦 ′′′′′ − 𝑦 ′′′ = 0. >> syms y(x) >> ode = diff(y,x,5)-diff(y,x,3) == 0; >> ySol(x) = dsolve(ode) Output: ySol(x) =C3 - C1 - C2*x - (C1*x^2)/2 + C5*exp(x) + C4*exp(-x) Higher order differential equations, Continued… Solve: 𝑦 ′′′′ − 3𝑦 ′′′ + 2𝑦 ′′ = 0, y 0 = 0, 𝑦 ′ 0 = 0, 𝑦 ′′ 0 = 2, 𝑦 ′′′ 0 = 2. >> syms y(x) >> Dy = diff(y); >> D2y = diff(y,2); >> D3y = diff(y,3); >> D4y = diff(y,4); >> ode = D4y - 3*D3y + 2*D2y == 0; >> ySol = dsolve(ode, y(0) == 0, Dy(0) == 0,D2y(0) == 2,D3y(0) == 2) Higher order differential equations, Continued… >> figure >> ezplot(ySol) Output: ySol = 2*exp(x) - 2*x - 2 Non-Homogeneous differential equations 𝑑2 𝑦 𝑑𝑦 Solve: −5 + 6𝑦 = 𝑒 5𝑥. 𝑑𝑥 2 𝑑𝑥 >> syms y(x) >> ode = diff(y,x,2)-5*diff(y,x,1)+6*y == exp(5*x); >> ySol(x) = dsolve(ode) Output: ySol(x) =exp(5*x)/6 + C1*exp(2*x) + C2*exp(3*x) Non-Homogeneous differential equations, Continued… 𝑑2 𝑦 𝑑𝑦 Solve: −4 + 4𝑦 = 2𝑒 2𝑥. 𝑑𝑥 2 𝑑𝑥 >> syms y(x) >> ode= diff(y,x,2)-4*diff(y,x,1)+4*y ==2*exp(2*x); >> ySol(x) = dsolve(ode) Output: ySol(x) =x^2*exp(2*x) + C1*exp(2*x) + C2*x*exp(2*x) Non-Homogeneous differential equations, Continued… Solve: 𝑦 ′′ +4𝑦 ′ + 13𝑦 = 18𝑒 −2𝑥 , y 0 = 0, 𝑦 ′ 0 = 4. >> syms y(x) >> Dy = diff(y); >> D2y = diff(y,2); >> ode = D2y + 4*Dy + 13*y == 18*exp(-2*x); >> ySol = dsolve(ode, y(0) == -1, Dy(0) == 4) >> figure >> ezplot(ySol) Non-Homogeneous differential equations, Continued… Output: Sol =exp(-2*x)*(2*sin(3*x) - 9*cos(3*x) + 6))/3 Non-Homogeneous differential equations, Continued… Solve: 𝐷3 + 𝐷2 − 𝐷 − 1 𝑦 = 𝑐𝑜𝑠2𝑥. >> syms y(x) >> ode= diff(y,x,3)+diff(y,x,2)-diff(y,x,1)-1*y == cos(2*x); >> ySol(x) = dsolve(ode) Output: ySol(x) = C3*exp(x) - (5^(1/2)*cos(2*x - atan(2)))/25 + C1*exp(-x) + C2*x*exp(-x) Non-Homogeneous differential equations, Continued… Solve: 𝐷2 + 4 𝑦 = 𝑠𝑖𝑛3𝑥 + 𝑐𝑜𝑠2𝑥. >> syms y(x) >> ode= diff(y,x,2)+4*y == sin(3*x)+cos(2*x); >> ySol(x) = dsolve(ode) Output: ySol(x) = cos(2*x)*(cos(4*x)/16 + sin(5*x)/20 - sin(x)/4 - 1/16) - sin(2*x)*(cos(5*x)/20 - x/4 - sin(4*x)/16 + cos(x)/4 + 3/10) + C1*cos(2*x) - C2*sin(2*x) Non-Homogeneous differential equations, Continued… Solve: 𝐷2 − 4𝐷 + 13 𝑦 = 8𝑠𝑖𝑛3𝑥, 𝑦 0 = 0, 𝑦 ′ 0 = 2. >> syms y(x) >> Dy = diff(y); >> D2y = diff(y,2); >> ode = D2y - 4*Dy + 13*y == 8*sin(3*x); >> ySol = dsolve(ode, y(0) == 1, Dy(0) == 2) >> figure >> ezplot(ySol) Non-Homogeneous differential equations, Continued… Output: ySol = cos(3*x)*(sin(6*x)/5 - cos(6*x)/15 + 2/3) - sin(3*x)*(cos(6*x)/5 + sin(6*x)/15) + (2*cos(3*x)*exp(2*x))/5 + (sin(3*x)*exp(2*x))/5 Non-Homogeneous differential equations, Continued… Solve: 𝑦 ′′ − 𝑦 = 1 + 𝑥 5 >> syms y(x) >> ode= diff(y,x,2)-y ==1+ x^5; >> ySol(x) = dsolve(ode) Output: ySol(x) = C2*exp(x) - 120*x - 20*x^3 - x^5 + C1*exp(-x) - 1 Non-Homogeneous differential equations, Continued… Solve: 𝑦 ′′ + 2𝑦 ′ + 𝑦 = 2𝑥 + 𝑥 2. >> syms y(x) >> ode= diff(y,x,2)+2*diff(y,x,1)+y == 2*x+x^2; >> ySol(x) = dsolve(ode) Output: ySol(x) =x^2 - 2*x + C1*exp(-x) + C2*x*exp(-x) + 2 Non-Homogeneous differential equations, Continued… 𝑑2 𝑦 𝑑𝑦 Solve: +2 − 3𝑦 = 𝑒 𝑥 𝑐𝑜𝑠𝑥. 𝑑𝑥 2 𝑑𝑥 >> syms y(x) >> ode= diff(y,x,2)+2*diff(y,x,1)-3*y == exp(x)*cos(x); >> ySol(x) = dsolve(ode) Output: ySol(x) = (exp(x)*sin(x))/4 + C2*exp(x) - (exp(x)*(4*cos(x) + sin(x)))/68 + C1*exp(-3*x) Non-Homogeneous differential equations, Continued… 𝑑2 𝑦 Solve: + 2𝑦 = 𝑒 3𝑥 𝑥 2. 𝑑𝑥 2 >> syms y(x) >> ode=diff(y,x,2)+2*y == exp(3*x)*x^2; >> ySol(x) = dsolve(ode) Output: ySol(x) = C1*cos(2^(1/2)*x)-C2*sin(2^(1/2)*x)+ (exp(3*x)*cos(2^(1/2)*x)*(100*cos(2^(1/2)*x) - 18*2^(1/2)*sin(2^(1/2)*x) - 264*x*cos(2^(1/2)*x)+242*x^2*cos(2^(1/2)*x)363*2^(1/2)*x^2*sin(2^(1/2) *x)+154*2^(1/2)*x*sin(2^(1/2)*x)))/2662+(exp(3*x)*sin(2^(1/2)*x)*+…….. THANK YOU ENGINEERING MATHEMATICS - I UNIT 4 : Partial Differential Equations and Special functions Session : 8 Department of Science and Humanities ENGINEERING MATHEMATICS - I Form the PDE by eliminating arbitrary constants: 𝑧 = (𝑥 − 𝑎)2 +(𝑦 − 𝑏)2 syms x y a b p q z=(x-a)^2+(y-b)^2; eq1=p==diff(z,x) c1=solve(eq1,a) eq2=q==diff(z,y) c2=solve(eq2,b) pde=subs(z,a,c1) pde=subs(pde,b,c2) Output: pde = p^2/4 + q^2/4 Partial differential equations Form the PDE by eliminating arbitrary constants: 𝑧 = 𝑥 + 𝑎 𝑦 + 𝑏) syms x y a b p q z=(x+a)*(y+b); eq1=p==diff(z,x) c1=solve(eq1,b) eq2=q==diff(z,y) c2=solve(eq2,a) pde=subs(z,b,c1) pde=subs(pde,a,c2) Partial differential equations 𝑥2 𝑦2 Form the PDE by eliminating arbitrary constants: 2𝑧 = + 𝑎2 𝑏2 syms x y a b p q z=x^2/(2*a^2)+y^2/(2*b^2) eq1=p==diff(z,x) c1=solve(eq1,a) eq2=q==diff(z,y) c2=solve(eq2,b) pde=subs(z,a,c1) pde=subs(pde,b,c2) ENGINEERING MATHEMATICS - I Beta and Gamma functions 3 7 1 3 1. Evaluate: Γ 0.5 , Γ 1 , Γ ,Γ ,Γ Γ 2 2 4 4 MATLAB CODE: gamma(0.5) gamma(1) gamma(3/2) gamma(7/2) gamma(1/4)* gamma(3/4) ENGINEERING MATHEMATICS - I 2. Evaluate several values of the gamma function between [-3.5 3.5]. MATLAB CODE: x = -3.5:3.5; y = gamma(x) MATLAB OUTPUT: y = 1×8 0.2701 -0.9453 2.3633 -3.5449 1.7725 0.8862 1.3293 3.3234 ENGINEERING MATHEMATICS - I Graph of gamma function 3. Use fplot to plot the gamma function and its reciprocal. fplot(@gamma) hold on fplot(@(x) 1./gamma(x)) hold off legend('\Gamma(x)','1/\Gamma(x)') grid on Gamma function Geometrical representation of Gamma function: Gamma function (Or) Geometrical representation of Gamma function: Γ 𝑛 = ∞ −𝑥 𝑛−1 0 𝑒 𝑥 𝑑𝑥; 𝑛 >0 fplot(@gamma) hold on fplot(@(x) 1./gamma(x)) ylim([-10 10]) legend('\Gamma(x)','1/\Gamma(x)') hold off grid on Evaluation of Beta function 1. beta(2,3) ans = 0.0833 2. beta(2,5) ans = 0.0333 3. beta(0,1) ans = Inf ENGINEERING MATHEMATICS - I 4. Compute the beta function for integer arguments n=3 and m=1,...,10. MATLAB CODE: format rat B = beta((1:10)',3) THANK YOU Dr. G K Jagatheswari Department of Science & Humanities [email protected] ENGINEERING MATHEMATICS-I MATLAB Department of Science and Humanities Radius Of Curvature: 2 2 2 Find the radius of curvature of the curve 𝑥 + 𝑦 = 𝑎 at any point (x,y) 3 3 3 of the curve. >> syms x y a >> F(x,y)=x^(2/3)+y^(2/3)-a^(2/3); >> dy_dx = - diff(F,x)/diff(F,y) Output: dy_dx(x, y) =-y^(1/3)/x^(1/3) >> G(x,y)=-y^(1/3)/x^(1/3); >> a=diff(G,x); >> b=diff(G,y); >> c=a+b*G(x,y) Out put: c(x, y) =1/(3*x^(2/3)*y^(1/3)) + y^(1/3)/(3*x^(4/3)) Radius Of Curvature, Continued… >> simplify(c) Out put: (x, y) =(x^(2/3) + y^(2/3))/(3*x^(4/3)*y^(1/3)) >> d=(1+G(x,y)^2)^(3/2) Out put: d =(y^(2/3)/x^(2/3) + 1)^(3/2) >> rho=d/c Output: rho(x, y) =(y^(2/3)/x^(2/3) + 1)^(3/2)/(1/(3*x^(2/3)*y^(1/3)) + y^(1/3)/(3*x^(4/3))) >> simplify(rho(x,y)) Output: (y^(2/3)/x^(2/3) + 1)^(3/2)/(1/(3*x^(2/3)*y^(1/3)) + y^(1/3)/(3*x^(4/3))) Radius Of Curvature, Continued… Find the radius of curvature of the curve 𝑥𝑦 = 𝑎2 at any point (x,y) of the curve. >> syms x y a >> F(x,y)=x*y-a^2; >> dy_dx = - diff(F,x)/diff(F,y) Output: dy_dx(x, y) =-y/x >> G(x,y)=-y/x; >> a=diff(G,x); >> b=diff(G,y); >> c=a+b*G(x,y) Output: c(x, y) =(2*y)/x^2 Radius Of Curvature, Continued… >> d=(1+G(x,y)^2)^(3/2) Output: d =(y^2/x^2 + 1)^(3/2) >> rho=d/c Output: rho(x, y) =(x^2*(y^2/x^2 + 1)^(3/2))/(2*y) >> simplify(rho) Output: (x, y) =(x^2*(y^2/x^2 + 1)^(3/2))/(2*y) Radius Of Curvature, Continued… Find the radius of curvature of the curve 𝑟 = 𝑒 2𝜃 at any point on the curve. >> syms theta >> r=exp(2*theta); >> r1=diff(r,theta); >> r2=diff(diff(r,theta)); >> a=(r^2+r1^2)^(3/2) Output: a =(5*exp(4*theta))^(3/2) >> b=r^2+2*r1^2-r*r2 Out put: b =5*exp(4*theta) >> rho=a/b Output: rho =(exp(-4*theta)*(5*exp(4*theta))^(3/2))/5 Radius Of Curvature, Continued… >> simplify(rho) Out put: 5^(1/2)*exp(4*theta)^(1/2) Radius Of Curvature Continued… Find the radius of curvature of the parametric curve 𝑥 = 6𝑡 2 − 3𝑡 4 , 𝑦 = 8𝑡 3. >> syms t >> x=6*t^2-3*t^4; >> x1=diff(x,t); >> x2=diff(diff(x,t)); >> y=8*t^3; >> y1=diff(y,t); >> y2=diff(diff(y,t)); >> a=(x1^2+y1^2) Output: a =(- 12*t^3 + 12*t)^2 + 576*t^4 >> b=simplify(a) Output: b =144*t^2*(t^2 + 1)^2 Radius Of Curvature, Continued… >> c=(x1*y2)-(y1*x2) Output: c =48*t*(- 12*t^3 + 12*t) + 24*t^2*(36*t^2 - 12) >> d=simplify(c) Output: d =288*t^2*(t^2 + 1) >> e=b^(3/2) Output: e =(144*t^2*(t^2 + 1)^2)^(3/2) >>rho=e/d Out put: rho =(144*t^2*(t^2 + 1)^2)^(3/2)/(288*t^2*(t^2 + 1)) >>simplify(rho) Output: rho= (6*(t^2*(t^2 + 1)^2)^(3/2))/(t^2*(t^2 + 1)) THANK YOU