*22/12/2021*

राष्ट्रीय गणित दिवस की हार्दिक शुभ कामना

This Page is a education platform for MATLAB lovers

Operating as usual

राष्ट्रीय गणित दिवस की हार्दिक शुभ कामना

आप सभी MATLABi किस विषय पर पोस्ट चाहते हैं?? गणित सप्तकदिवस विशेष

आज की क्लास है, करियर चुनाव भाग 1

एक एयरबग्स वाला निक बैंड यूज करें8💐💐💐महादेव

Introduction: -The word "fuzzy" means "vagueness". Fuzziness occurs when the boundary of a piece of information is not clear-cut. Fuzzy sets have been introduced by Lotfi A. Zadeh (1965) as an extension of the classical notion of set. Classical set theory allows the membership of the elements in the se in binary terms, a bivalent condition - an element either belongs or does not belong to the set.

Fuzzy set theory permits the gradual assessment of the membership of elements in a set, described with the aid of a membership function valued in the real unit interval [0, 1].

Example:

Words like young, tall, good, or high are fuzzy.

− There is no single quantitative value which defines the term young.

− For some people, age 25 is young, and for others, age 35 is young.

− The concept young has no clean boundary.

− Age 1 is definitely young and age 100 is definitely not young.

− Age 35 has some possibility of being young and usually depends on the context in which it is being considered.

In real world, there exists much fuzzy knowledge; Knowledge that is vague, imprecise, uncertain, ambiguous, inexact, or probabilistic in nature. Human thinking and reasoning frequently involve fuzzy information, originating from inherently inexact human concepts. Humans, can give satisfactory answers, which are probably true. However, our systems are unable to answer many questions. The reason is, most systems are designed based upon classical set theory and two-valued logic which is unable to cope with unreliable and incomplete information and give expert opinions. our systems should also be able to cope with unreliable and incomplete information and give expert opinions. Fuzzy sets have been able provide solutions to many real world problems. Fuzzy Set theory is an extension of classical set theory where elements have degrees of membership.

Fuzzy Set Theory

Fuzzy set theory is an extension of classical set theory where elements have varying degrees of membership. A logic based on the two truth values, True and False, is sometimes inadequate when describing human reasoning. Fuzzy logic uses the whole interval between 0 (false) and 1 (true) to describe human reasoning.

− A Fuzzy Set is any set that allows its members to have different degree of membership, called membership function, in the interval [0 , 1].

- The degree of membership or truth is not same as probability; fuzzy truth is not likelihood of some event or condition. Fuzzy truth represents membership in vaguely defined sets.

− Fuzzy logic is derived from fuzzy set theory dealing with reasoning that is approximate rather than precisely deduced from classical predicate logic.

− Fuzzy logic is capable of handling inherently imprecise concepts.

− Fuzzy logic allows in linguistic form the set membership values to imprecise concepts like "slightly", "quite" and "very".

− Fuzzy set theory defines Fuzzy Operators on Fuzzy Sets.

Dr Sanjeev Kumar

Er Ashish Nishad

Introduction:-A neural network is a massively parallel distributed processor made up of simple processing units, which has a natural propensity for storing experiential knowledge and making it available for use. It resembles the brain in two respects:

1. Knowledge is acquired by the network from its environment through a learning process.

2. Interneuron connection strengths, known as synaptic weights, are used to store the acquired knowledge. Neural networks are also referred to in literature as neurocomputers, connectionist networks. Parallel distributed processors, etc.

Benefits of Neural Networks

The use of neural networks offers the following useful properties and capabilities:

1.Nonlinearity. An artificial neuron can be linear or nonlinear. A neural network, made up of an interconnection of nonlinear neurons, is itself nonlinear. The nonlinearity is of a special kind in the sense that it is distributed throughout the network.

2.Input-Output Mapping. The network learns from the examples by constructing an input-output mappingfor the problem at hand. Such an approach brings to mind the study of nonparametricstatistical inference; the term"nonparametric" is used here to signify the fact that no prior assumptions are made ona statistical model for the input data.

3.Adaptivity. Neural networks have a built-in capability to adapt their synapticweights to changes in the surrounding environment. In particular, a neural networktrained to operate in a specific environment can be easily retrained to deal with minorchanges in the operating environmental conditions. Moreover, when it is operating in anonstationary environment, a neural networkcan be designed to change its synaptic weights in real time.

4.Evidential Response. In the context of pattern classification, a neural networkcan be designed to provide information not only about which particular pattern toselect, but also about the confidence in the decision made. This latter information maybe used to reject ambiguous patterns, should they arise, and thereby improve the classificationperformance of the network.

5.Contextual Information. Knowledge is represented by the very structure andactivation state of a neural network. Every neuron in the network is potentiallyaffected by the global activity of all other neurons in the network. Consequently, contextualinformation is dealt with naturally by a neural network.

6.Fault Tolerance. A neural network, implemented in hardware form, has thepotential to be inherently fault tolerant, or capable of robust computation, in thesense that its performance degrades gracefully under adverse operating conditions.

7.VLSI Implement ability.The massively parallel nature of a neural network makes it potentially fast for the computation of certain tasks. This same feature makes a neural network well suited for implementation using very-large-scale-integrated(VLSI) technology. One particular beneficial virtue of VLSI is that it provides a means of capturing truly complex behavior in a highly hierarchical fashion.

8.Uniformity of Analysis and Design. Basically, neural networks enjoy universality as information processors. We say this in the sense that the same notation is used in all domains involving the application of neural networks. This feature manifests itself in different ways:

Neurons, in one form or another, represent an ingredient common to all neural networks.

This commonality makes it possible to share theories and learning algorithms in different applications of neural networks.

Modular networks can be built through a seamless integration of modules.

9.Neurobiological Analogy. The design of a neural network is motivated by analogy with the brain, which is a living proof that fault tolerant parallel processing is not only physically possible but also fast and powerful. Neurobiologists look to (artificial) neural networks as a research tool for the interpretation of neurobiological phenomena.

Er. Ashish Nishad

Fuzzy Neural Networks Introduction

for

MATLAB provides the diff command for computing symbolic derivatives. In its simplest form, you pass the function you want to differentiate to diff command as an argument.

For example, let us compute the derivative of the function f(t) = 3t2 + 2t-2

Example

Create a script file and type the following code into it −

syms t

f = 3*t^2 + 2*t^(-2);

diff(f)

When the above code is compiled and executed, it produces the following result −

ans =

6*t - 4/t^3

Following is Octave equivalent of the above calculation −

pkg load symbolic

symbols

t = sym("t");

f = 3*t^2 + 2*t^(-2);

differentiate(f,t)

Octave executes the code and returns the following result −

ans =

-(4.0)*t^(-3.0)+(6.0)*t

Verification of Elementary Rules of Differentiation

Let us briefly state various equations or rules for differentiation of functions and verify these rules. For this purpose, we will write f'(x) for a first order derivative and f"(x) for a second order derivative.

Following are the rules for differentiation −

Rule 1

For any functions f and g and any real numbers a and b are the derivative of the function:

h(x) = af(x) + bg(x) with respect to x is given by −

h'(x) = af'(x) + bg'(x)

Rule 2

The sum and subtraction rules state that if f and g are two functions, f' and g' are their derivatives respectively, then,

(f + g)' = f' + g'

(f - g)' = f' - g'

Rule 3

The product rule states that if f and g are two functions, f' and g' are their derivatives respectively, then,

(f.g)' = f'.g + g'.f

Rule 4

The quotient rule states that if f and g are two functions, f' and g' are their derivatives respectively, then,

(f/g)' = (f'.g - g'.f)/g2

Rule 5

The polynomial or elementary power rule states that, if y = f(x) = xn, then f' = n. x(n-1)

A direct outcome of this rule is that the derivative of any constant is zero, i.e., if y = k, any constant, then

f' = 0

Rule 6

The chain rule states that, derivative of the function of a function h(x) = f(g(x)) with respect to x is,

h'(x)= f'(g(x)).g'(x)

Example

Create a script file and type the following code into it −

syms x

syms t

f = (x + 2)*(x^2 + 3)

der1 = diff(f)

f = (t^2 + 3)*(sqrt(t) + t^3)

der2 = diff(f)

f = (x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2)

der3 = diff(f)

f = (2*x^2 + 3*x)/(x^3 + 1)

der4 = diff(f)

f = (x^2 + 1)^17

der5 = diff(f)

f = (t^3 + 3* t^2 + 5*t -9)^(-6)

der6 = diff(f)

When you run the file, MATLAB displays the following result −

f =

(x^2 + 3)*(x + 2)

der1 =

2*x*(x + 2) + x^2 + 3

f =

(t^(1/2) + t^3)*(t^2 + 3)

der2 =

(t^2 + 3)*(3*t^2 + 1/(2*t^(1/2))) + 2*t*(t^(1/2) + t^3)

f =

(x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2)

der3 =

(2*x - 2)*(3*x^3 - 5*x^2 + 2) - (- 9*x^2 + 10*x)*(x^2 - 2*x + 1)

f =

(2*x^2 + 3*x)/(x^3 + 1)

der4 =

(4*x + 3)/(x^3 + 1) - (3*x^2*(2*x^2 + 3*x))/(x^3 + 1)^2

f =

(x^2 + 1)^17

der5 =

34*x*(x^2 + 1)^16

f =

1/(t^3 + 3*t^2 + 5*t - 9)^6

der6 =

-(6*(3*t^2 + 6*t + 5))/(t^3 + 3*t^2 + 5*t - 9)^7

Following is Octave equivalent of the above calculation −

pkg load symbolic

symbols

x=sym("x");

t=sym("t");

f = (x + 2)*(x^2 + 3)

der1 = differentiate(f,x)

f = (t^2 + 3)*(t^(1/2) + t^3)

der2 = differentiate(f,t)

f = (x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2)

der3 = differentiate(f,x)

f = (2*x^2 + 3*x)/(x^3 + 1)

der4 = differentiate(f,x)

f = (x^2 + 1)^17

der5 = differentiate(f,x)

f = (t^3 + 3* t^2 + 5*t -9)^(-6)

der6 = differentiate(f,t)

Octave executes the code and returns the following result −

f =

(2.0+x)*(3.0+x^(2.0))

der1 =

3.0+x^(2.0)+(2.0)*(2.0+x)*x

f =

(t^(3.0)+sqrt(t))*(3.0+t^(2.0))

der2 =

(2.0)*(t^(3.0)+sqrt(t))*t+((3.0)*t^(2.0)+(0.5)*t^(-0.5))*(3.0+t^(2.0))

f =

(1.0+x^(2.0)-(2.0)*x)*(2.0-(5.0)*x^(2.0)+(3.0)*x^(3.0))

der3 =

(-2.0+(2.0)*x)*(2.0-(5.0)*x^(2.0)+(3.0)*x^(3.0))+((9.0)*x^(2.0)-(10.0)*x)*(1.0+x^(2.0)-(2.0)*x)

f =

(1.0+x^(3.0))^(-1)*((2.0)*x^(2.0)+(3.0)*x)

der4 =

(1.0+x^(3.0))^(-1)*(3.0+(4.0)*x)-(3.0)*(1.0+x^(3.0))^(-2)*x^(2.0)*((2.0)*x^(2.0)+(3.0)*x)

f =

(1.0+x^(2.0))^(17.0)

der5 =

(34.0)*(1.0+x^(2.0))^(16.0)*x

f =

(-9.0+(3.0)*t^(2.0)+t^(3.0)+(5.0)*t)^(-6.0)

der6 =

-(6.0)*(-9.0+(3.0)*t^(2.0)+t^(3.0)+(5.0)*t)^(-7.0)*(5.0+(3.0)*t^(2.0)+(6.0)*t)

Derivatives of Exponential, Logarithmic and Trigonometric Functions

The following table provides the derivatives of commonly used exponential, logarithmic and trigonometric functions −

Function Derivative

ca.x ca.x.ln c.a (ln is natural logarithm)

ex ex

ln x 1/x

lncx 1/x.ln c

xx xx.(1 + ln x)

sin(x) cos(x)

cos(x) -sin(x)

tan(x) sec2(x), or 1/cos2(x), or 1 + tan2(x)

cot(x) -csc2(x), or -1/sin2(x), or -(1 + cot2(x))

sec(x) sec(x).tan(x)

csc(x) -csc(x).cot(x)

Example

Create a script file and type the following code into it −

syms x

y = exp(x)

diff(y)

y = x^9

diff(y)

y = sin(x)

diff(y)

y = tan(x)

diff(y)

y = cos(x)

diff(y)

y = log(x)

diff(y)

y = log10(x)

diff(y)

y = sin(x)^2

diff(y)

y = cos(3*x^2 + 2*x + 1)

diff(y)

y = exp(x)/sin(x)

diff(y)

Prof Sanjeev Kumar

Er Ashish Nishad

When you run the file, MATLAB displays the following result −

for

MATLAB provides various ways for solving problems of differential and integral calculus, solving differential equations of any degree and calculation of limits. Best of all, you can easily plot the graphs of complex functions and check maxima, minima and other stationery points on a graph by solving the original function, as well as its derivative.

This chapter will deal with problems of calculus. In this chapter, we will discuss pre-calculus concepts i.e., calculating limits of functions and verifying the properties of limits.

In the next chapter Differential, we will compute derivative of an expression and find the local maxima and minima on a graph. We will also discuss solving differential equations.

Finally, in the Integration chapter, we will discuss integral calculus.

Calculating Limits

MATLAB provides the limit function for calculating limits. In its most basic form, the limit function takes expression as an argument and finds the limit of the expression as the independent variable goes to zero.

For example, let us calculate the limit of a function f(x) = (x3 + 5)/(x4 + 7), as x tends to zero.

syms x

limit((x^3 + 5)/(x^4 + 7))

MATLAB will execute the above statement and return the following result −

ans =

5/7

The limit function falls in the realm of symbolic computing; you need to use the syms function to tell MATLAB which symbolic variables you are using. You can also compute limit of a function, as the variable tends to some number other than zero. To calculate lim x->a(f(x)), we use the limit command with arguments. The first being the expression and the second is the number, that x approaches, here it is a.

For example, let us calculate limit of a function f(x) = (x-3)/(x-1), as x tends to 1.

limit((x - 3)/(x-1),1)

MATLAB will execute the above statement and return the following result −

ans =

NaN

Let's take another example,

limit(x^2 + 5, 3)

MATLAB will execute the above statement and return the following result −

ans =

14

Calculating Limits using Octave

Following is Octave version of the above example using symbolic package, try to execute and compare the result −

pkg load symbolic

symbols

x=sym("x");

subs((x^3+5)/(x^4+7),x,0)

Octave will execute the above statement and return the following result −

ans =

0.7142857142857142857

Verification of Basic Properties of Limits

Algebraic Limit Theorem provides some basic properties of limits. These are as follows −

Let us consider two functions −

f(x) = (3x + 5)/(x - 3)

g(x) = x2 + 1.

Let us calculate the limits of the functions as x tends to 5, of both functions and verify the basic properties of limits using these two functions and MATLAB.

Example

Create a script file and type the following code into it −

syms x

f = (3*x + 5)/(x-3);

g = x^2 + 1;

l1 = limit(f, 4)

l2 = limit (g, 4)

lAdd = limit(f + g, 4)

lSub = limit(f - g, 4)

lMult = limit(f*g, 4)

lDiv = limit (f/g, 4)

When you run the file, it displays −

l1 =

17

l2 =

17

lAdd =

34

lSub =

0

lMult =

289

lDiv =

1

Verification of Basic Properties of Limits using Octave

Following is Octave version of the above example using symbolic package, try to execute and compare the result −

pkg load symbolic

symbols

x = sym("x");

f = (3*x + 5)/(x-3);

g = x^2 + 1;

l1=subs(f, x, 4)

l2 = subs (g, x, 4)

lAdd = subs (f+g, x, 4)

lSub = subs (f-g, x, 4)

lMult = subs (f*g, x, 4)

lDiv = subs (f/g, x, 4)

Octave will execute the above statement and return the following result −

l1 =

17.0

l2 =

17.0

lAdd =

34.0

lSub =

0.0

lMult =

289.0

lDiv =

1.0

Left and Right Sided Limits

When a function has a discontinuity for some particular value of the variable, the limit does not exist at that point. In other words, limits of a function f(x) has discontinuity at x = a, when the value of limit, as x approaches x from left side, does not equal the value of the limit as x approaches from right side.

This leads to the concept of left-handed and right-handed limits. A left-handed limit is defined as the limit as x -> a, from the left, i.e., x approaches a, for values of x < a. A right-handed limit is defined as the limit as x -> a, from the right, i.e., x approaches a, for values of x > a. When the left-handed limit and right-handed limit are not equal, the limit does not exist.

Let us consider a function −

f(x) = (x - 3)/|x - 3|

We will show that limx->3 f(x) does not exist. MATLAB helps us to establish this fact in two ways −

By plotting the graph of the function and showing the discontinuity.

By computing the limits and showing that both are different.

The left-handed and right-handed limits are computed by passing the character strings 'left' and 'right' to the limit command as the last argument.

Example

Create a script file and type the following code into it −

f = (x - 3)/abs(x-3);

ezplot(f,[-1,5])

l = limit(f,x,3,'left')

r = limit(f,x,3,'right')

When you run the file, MATLAB draws the following plot

After this following output is displayed −

l =

-1

r =

1

Prof Sanjeev Kumar

Er Ashish Nishad

Calculus for Matlab

MATLAB provides various ways for solving problems of differential and integral calculus, solving differential equations of any degree and calculation of limits. Best of all, you can easily plot the graphs of complex functions and check maxima, minima and other stationery points on a graph by solving the original function, as well as its derivative.

This chapter will deal with problems of calculus. In this chapter, we will discuss pre-calculus concepts i.e., calculating limits of functions and verifying the properties of limits.

In the next chapter Differential, we will compute derivative of an expression and find the local maxima and minima on a graph. We will also discuss solving differential equations.

Finally, in the Integration chapter, we will discuss integral calculus.

Calculating Limits

MATLAB provides the limit function for calculating limits. In its most basic form, the limit function takes expression as an argument and finds the limit of the expression as the independent variable goes to zero.

For example, let us calculate the limit of a function f(x) = (x3 + 5)/(x4 + 7), as x tends to zero.

syms x

limit((x^3 + 5)/(x^4 + 7))

MATLAB will execute the above statement and return the following result −

ans =

5/7

The limit function falls in the realm of symbolic computing; you need to use the syms function to tell MATLAB which symbolic variables you are using. You can also compute limit of a function, as the variable tends to some number other than zero. To calculate lim x->a(f(x)), we use the limit command with arguments. The first being the expression and the second is the number, that x approaches, here it is a.

For example, let us calculate limit of a function f(x) = (x-3)/(x-1), as x tends to 1.

limit((x - 3)/(x-1),1)

MATLAB will execute the above statement and return the following result −

ans =

NaN

Let's take another example,

limit(x^2 + 5, 3)

MATLAB will execute the above statement and return the following result −

ans =

14

Calculating Limits using Octave

Following is Octave version of the above example using symbolic package, try to execute and compare the result −

pkg load symbolic

symbols

x=sym("x");

subs((x^3+5)/(x^4+7),x,0)

Octave will execute the above statement and return the following result −

ans =

0.7142857142857142857

Verification of Basic Properties of Limits

Algebraic Limit Theorem provides some basic properties of limits. These are as follows −

Let us consider two functions −

f(x) = (3x + 5)/(x - 3)

g(x) = x2 + 1.

Let us calculate the limits of the functions as x tends to 5, of both functions and verify the basic properties of limits using these two functions and MATLAB.

Example

Create a script file and type the following code into it −

syms x

f = (3*x + 5)/(x-3);

g = x^2 + 1;

l1 = limit(f, 4)

l2 = limit (g, 4)

lAdd = limit(f + g, 4)

lSub = limit(f - g, 4)

lMult = limit(f*g, 4)

lDiv = limit (f/g, 4)

When you run the file, it displays −

l1 =

17

l2 =

17

lAdd =

34

lSub =

0

lMult =

289

lDiv =

1

Verification of Basic Properties of Limits using Octave

Following is Octave version of the above example using symbolic package, try to execute and compare the result −

pkg load symbolic

symbols

x = sym("x");

f = (3*x + 5)/(x-3);

g = x^2 + 1;

l1=subs(f, x, 4)

l2 = subs (g, x, 4)

lAdd = subs (f+g, x, 4)

lSub = subs (f-g, x, 4)

lMult = subs (f*g, x, 4)

lDiv = subs (f/g, x, 4)

Octave will execute the above statement and return the following result −

l1 =

17.0

l2 =

17.0

lAdd =

34.0

lSub =

0.0

lMult =

289.0

lDiv =

1.0

Left and Right Sided Limits

When a function has a discontinuity for some particular value of the variable, the limit does not exist at that point. In other words, limits of a function f(x) has discontinuity at x = a, when the value of limit, as x approaches x from left side, does not equal the value of the limit as x approaches from right side.

This leads to the concept of left-handed and right-handed limits. A left-handed limit is defined as the limit as x -> a, from the left, i.e., x approaches a, for values of x < a. A right-handed limit is defined as the limit as x -> a, from the right, i.e., x approaches a, for values of x > a. When the left-handed limit and right-handed limit are not equal, the limit does not exist.

Let us consider a function −

f(x) = (x - 3)/|x - 3|

We will show that limx->3 f(x) does not exist. MATLAB helps us to establish this fact in two ways −

By plotting the graph of the function and showing the discontinuity.

By computing the limits and showing that both are different.

The left-handed and right-handed limits are computed by passing the character strings 'left' and 'right' to the limit command as the last argument.

Example

Create a script file and type the following code into it −

f = (x - 3)/abs(x-3);

ezplot(f,[-1,5])

l = limit(f,x,3,'left')

r = limit(f,x,3,'right')

When you run the file, MATLAB draws the following plot

After this following output is displayed −

l =

-1

r =

1

for

So far, we have seen that all the examples work in MATLAB as well as its GNU, alternatively called Octave. But for solving basic algebraic equations, both MATLAB and Octave are little different, so we will try to cover MATLAB and Octave in separate sections.

We will also discuss factorizing and simplification of algebraic expressions.

Solving Basic Algebraic Equations in MATLAB

The solve function is used for solving algebraic equations. In its simplest form, the solve function takes the equation enclosed in quotes as an argument.

For example, let us solve for x in the equation x-5 = 0

solve('x-5=0')

MATLAB will execute the above statement and return the following result −

ans =

5

You can also call the solve function as −

y = solve('x-5 = 0')

MATLAB will execute the above statement and return the following result −

y =

5

You may even not include the right hand side of the equation −

solve('x-5')

MATLAB will execute the above statement and return the following result −

ans =

5

If the equation involves multiple symbols, then MATLAB by default assumes that you are solving for x, however, the solve function has another form −

solve(equation, variable)

where, you can also mention the variable.

For example, let us solve the equation v – u – 3t2 = 0, for v. In this case, we should write −

solve('v-u-3*t^2=0', 'v')

MATLAB will execute the above statement and return the following result −

ans =

3*t^2 + u

Solving Basic Algebraic Equations in Octave

The roots function is used for solving algebraic equations in Octave and you can write above examples as follows:

For example, let us solve for x in the equation x-5 = 0

roots([1, -5])

Octave will execute the above statement and return the following result −

ans = 5

You can also call the solve function as −

y = roots([1, -5])

Octave will execute the above statement and return the following result −

y = 5

Solving Quadratic Equations in MATLAB

The solve function can also solve higher order equations. It is often used to solve quadratic equations. The function returns the roots of the equation in an array.

The following example solves the quadratic equation x2 -7x +12 = 0. Create a script file and type the following code −

eq = 'x^2 -7*x + 12 = 0';

s = solve(eq);

disp('The first root is: '), disp(s(1));

disp('The second root is: '), disp(s(2));

When you run the file, it displays the following result −

The first root is:

3

The second root is:

4

Solving Quadratic Equations in Octave

The following example solves the quadratic equation x2 -7x +12 = 0 in Octave. Create a script file and type the following code −

s = roots([1, -7, 12]);

disp('The first root is: '), disp(s(1));

disp('The second root is: '), disp(s(2));

When you run the file, it displays the following result −

The first root is:

4

The second root is:

3

Solving Higher Order Equations in MATLAB

The solve function can also solve higher order equations. For example, let us solve a cubic equation as (x-3)2(x-7) = 0

solve('(x-3)^2*(x-7)=0')

MATLAB will execute the above statement and return the following result −

ans =

3

3

7

In case of higher order equations, roots are long containing many terms. You can get the numerical value of such roots by converting them to double. The following example solves the fourth order equation x4 − 7x3 + 3x2 − 5x + 9 = 0.

Create a script file and type the following code −

eq = 'x^4 - 7*x^3 + 3*x^2 - 5*x + 9 = 0';

s = solve(eq);

disp('The first root is: '), disp(s(1));

disp('The second root is: '), disp(s(2));

disp('The third root is: '), disp(s(3));

disp('The fourth root is: '), disp(s(4));

% converting the roots to double type

disp('Numeric value of first root'), disp(double(s(1)));

disp('Numeric value of second root'), disp(double(s(2)));

disp('Numeric value of third root'), disp(double(s(3)));

disp('Numeric value of fourth root'), disp(double(s(4)));

When you run the file, it returns the following result −

The first root is:

6.630396332390718431485053218985

The second root is:

1.0597804633025896291682772499885

The third root is:

- 0.34508839784665403032666523448675 - 1.0778362954630176596831109269793*i

The fourth root is:

- 0.34508839784665403032666523448675 + 1.0778362954630176596831109269793*i

Numeric value of first root

6.6304

Numeric value of second root

1.0598

Numeric value of third root

-0.3451 - 1.0778i

Numeric value of fourth root

-0.3451 + 1.0778i

Please note that the last two roots are complex numbers.

Solving Higher Order Equations in Octave

The following example solves the fourth order equation x4 − 7x3 + 3x2 − 5x + 9 = 0.

Create a script file and type the following code −

v = [1, -7, 3, -5, 9];

s = roots(v);

% converting the roots to double type

disp('Numeric value of first root'), disp(double(s(1)));

disp('Numeric value of second root'), disp(double(s(2)));

disp('Numeric value of third root'), disp(double(s(3)));

disp('Numeric value of fourth root'), disp(double(s(4)));

When you run the file, it returns the following result −

Numeric value of first root

6.6304

Numeric value of second root

-0.34509 + 1.07784i

Numeric value of third root

-0.34509 - 1.07784i

Numeric value of fourth root

1.0598

Solving System of Equations in MATLAB

The solve function can also be used to generate solutions of systems of equations involving more than one variables. Let us take up a simple example to demonstrate this use.

Let us solve the equations −

5x + 9y = 5

3x – 6y = 4

Create a script file and type the following code −

s = solve('5*x + 9*y = 5','3*x - 6*y = 4');

s.x

s.y

When you run the file, it displays the following result −

ans =

22/19

ans =

-5/57

In same way, you can solve larger linear systems. Consider the following set of equations −

x + 3y -2z = 5

3x + 5y + 6z = 7

2x + 4y + 3z = 8

Solving System of Equations in Octave

We have a little different approach to solve a system of 'n' linear equations in 'n' unknowns. Let us take up a simple example to demonstrate this use.

Let us solve the equations −

5x + 9y = 5

3x – 6y = 4

Such a system of linear equations can be written as the single matrix equation Ax = b, where A is the coefficient matrix, b is the column vector containing the right-hand side of the linear equations and x is the column vector representing the solution as shown in the below program −

Create a script file and type the following code −

A = [5, 9; 3, -6];

b = [5;4];

A \ b

When you run the file, it displays the following result −

ans =

1.157895

-0.087719

In same way, you can solve larger linear systems as given below −

x + 3y -2z = 5

3x + 5y + 6z = 7

2x + 4y + 3z = 8

Expanding and Collecting Equations in MATLAB

The expand and the collect function expands and collects an equation respectively. The following example demonstrates the concepts −

When you work with many symbolic functions, you should declare that your variables are symbolic.

Create a script file and type the following code −

syms x %symbolic variable x

syms y %symbolic variable x

% expanding equations

expand((x-5)*(x+9))

expand((x+2)*(x-3)*(x-5)*(x+7))

expand(sin(2*x))

expand(cos(x+y))

%

Prof Sanjeev Kumar

Er Ashish Nishad

सभी पीएचडी स्कोलर जो एडवांस MATLAB की ऑनलाइन क्लास लेना चाहते हैं पेज से जुड़े। आपका स्वागत है।

for

This chapter will continue exploring the plotting and graphics capabilities of MATLAB. We will discuss −

Drawing bar charts

Drawing contours

Three dimensional plots

Drawing Bar Charts

The bar command draws a two dimensional bar chart. Let us take up an example to demonstrate the idea.

Example

Let us have an imaginary classroom with 10 students. We know the percent of marks obtained by these students are 75, 58, 90, 87, 50, 85, 92, 75, 60 and 95. We will draw the bar chart for this data.

Create a script file and type the following code −

x = [1:10];

y = [75, 58, 90, 87, 50, 85, 92, 75, 60, 95];

bar(x,y), xlabel('Student'),ylabel('Score'),

title('First Sem:')

print -deps graph.eps

When you run the file, MATLAB displays the following bar chart −

Drawing Contours

A contour line of a function of two variables is a curve along which the function has a constant value. Contour lines are used for creating contour maps by joining points of equal elevation above a given level, such as mean sea level.

MATLAB provides a contour function for drawing contour maps.

Example

Let us generate a contour map that shows the contour lines for a given function g = f(x, y). This function has two variables. So, we will have to generate two independent variables, i.e., two data sets x and y. This is done by calling the meshgrid command.

The meshgrid command is used for generating a matrix of elements that give the range over x and y along with the specification of increment in each case.

Let us plot our function g = f(x, y), where −5 ≤ x ≤ 5, −3 ≤ y ≤ 3. Let us take an increment of 0.1 for both the values. The variables are set as −

[x,y] = meshgrid(–5:0.1:5, –3:0.1:3);

Lastly, we need to assign the function. Let our function be: x2 + y2

Create a script file and type the following code −

[x,y] = meshgrid(-5:0.1:5,-3:0.1:3); %independent variables

g = x.^2 + y.^2; % our function

contour(x,y,g) % call the contour function

print -deps graph.eps

When you run the file, MATLAB displays the following contour map −

Let us modify the code a little to spruce up the map

[x,y] = meshgrid(-5:0.1:5,-3:0.1:3); %independent variables

g = x.^2 + y.^2; % our function

[C, h] = contour(x,y,g); % call the contour function

set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)

print -deps graph.eps

When you run the file, MATLAB displays the following contour map −

Three Dimensional Plots

Three-dimensional plots basically display a surface defined by a function in two variables, g = f (x,y).

As before, to define g, we first create a set of (x,y) 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.

The following example demonstrates the concept −

Example

Let us create a 3D surface map for the function g = xe-(x2 + y2)

Create a script file and type the following code −

[x,y] = meshgrid(-2:.2:2);

g = x .* exp(-x.^2 - y.^2);

surf(x, y, g)

print -deps graph.eps

When you run the file, MATLAB displays the following 3-D map −

You can also use the mesh command to generate a three-dimensional surface. However, the surf command displays both the connecting lines and the faces of the surface in color, whereas, the mesh command creates a wireframe surface with colored lines connecting the defining points.

।

।

Prof Sanjeev kumar

Er Ashish Nishad

Want your school to be the top-listed School/college in Agar?

Click here to claim your Sponsored Listing.

Click here to claim your Sponsored Listing.

Agar

Other Education in Agar (show all)

Kumbhkar coaching classes

Piplon Kalan

Agar, 465441

Piplon Kalan

Agar, 465441

शिक्षा का अर्थ है सीखना और हमारा लक्ष्य है आपको हमेशा सिखाते रहना l

Neel kantheshwar Convent Higher Secondary School

Pal Road, Master Colony

Agar

Pal Road, Master Colony

Agar

More to be even better