Numerical Methods in MATLAB

  • First Online: 08 March 2022

Cite this chapter

learning matlab problem solving and numerical analysis through examples

  • Eklas Hossain 2  

4442 Accesses

Numerical analysis is useful to solve numerous engineering problems encompassing several applications. Although there are many diverse and complicated branches of numerical analysis, only three important and reader-friendly methods are included in this chapter. This chapter aims to deliver the basics of the most commonly deployed numerical methods with worked out examples in MATLAB so that the readers get acquainted with the fundamental approach of numerical analysis. This concise chapter describes the Gauss-Seidel method, the Newton-Raphson method, and the Runge-Kutta method elaborately along with MATLAB examples for each method. Each of these three methods is first addressed theoretically with the mathematical equations, and then the MATLAB examples are suitably designed to help the readers understand how to solve different types of equations and also determine the tolerance of the solutions. Having completed this chapter, a reader will be able to solve equations using numerical methods such as the Gauss-Seidel, Newton-Raphson, and Runge-Kutta methods.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save.

  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
  • Available as EPUB and PDF
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
  • Durable hardcover edition

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and affiliations.

Oregon Institute of Technology, Klamath Falls, OR, USA

Eklas Hossain

You can also search for this author in PubMed   Google Scholar

Corresponding author

Correspondence to Eklas Hossain .

Write down the basic steps of the following:

Gauss-Seidel method

Newton-Raphson method

Runge-Kutta method

State the major differences in the calculation of the three methods mentioned in Question 1.

Given a set of equation as follows:

Solve the equation using Gauss-Seidel method in MATLAB. Consider the tolerance for x , y , and  z to be less than 0.00001.

What happens when you decrease the tolerance to 0.0001 and 0.001? Do the values vary from the values determined in question (a)? Why do you think this occurs?

What happens when you increase the tolerance to 0.000001 and 0.0000001? Do the values vary from the values determined in question (a)? Why do you think this occurs?

Solve the following equation using Newton-Raphson method, which has a root within the range of [0, 2]. Consider a tolerance for the value of root less than 0.0001:

3 x  + 2 cos ( x ) − 5

x 5  −  x  − 2

Use the classical fourth-order Runge-Kutta method to solve the following differential equations for the step size of 0.2, for 0 ≤  x  ≤ 2, and with an initial condition of y (0) = 5 in MATLAB:

\( \frac{dy}{dx}=-4{x}^3-6{x}^2-10x+2 \)

\( \frac{dy}{dx}= xsin(y)+y\cos (x) \)

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this chapter

Hossain, E. (2022). Numerical Methods in MATLAB. In: MATLAB and Simulink Crash Course for Engineers. Springer, Cham. https://doi.org/10.1007/978-3-030-89762-8_7

Download citation

DOI : https://doi.org/10.1007/978-3-030-89762-8_7

Published : 08 March 2022

Publisher Name : Springer, Cham

Print ISBN : 978-3-030-89761-1

Online ISBN : 978-3-030-89762-8

eBook Packages : Engineering Engineering (R0)

Share this chapter

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Publish with us

Policies and ethics

  • Find a journal
  • Track your research

Help Center Help Center

  • Help Center
  • Trial Software
  • Product Updates
  • Documentation

Train Network with Numeric Features

This example shows how to create and train a simple neural network for deep learning feature data classification.

If you have a data set of numeric features (for example a collection of numeric data without spatial or time dimensions), then you can train a deep learning network using a feature input layer. For an example showing how to train a network for image classification, see Create Simple Deep Learning Neural Network for Classification .

This example shows how to train a network to classify the gear tooth condition of a transmission system given a mixture of numeric sensor readings, statistics, and categorical labels.

Load the transmission casing dataset for training. The data set consists of 208 synthetic readings of a transmission system consisting of 18 numeric readings and three categorical labels:

SigMean — Vibration signal mean

SigMedian — Vibration signal median

SigRMS — Vibration signal RMS

SigVar — Vibration signal variance

SigPeak — Vibration signal peak

SigPeak2Peak — Vibration signal peak to peak

SigSkewness — Vibration signal skewness

SigKurtosis — Vibration signal kurtosis

SigCrestFactor — Vibration signal crest factor

SigMAD — Vibration signal MAD

SigRangeCumSum — Vibration signal range cumulative sum

SigCorrDimension — Vibration signal correlation dimension

SigApproxEntropy — Vibration signal approximate entropy

SigLyapExponent — Vibration signal Lyap exponent

PeakFreq — Peak frequency.

HighFreqPower — High frequency power

EnvPower — Environment power

PeakSpecKurtosis — Peak frequency of spectral kurtosis

SensorCondition — Condition of sensor, specified as "Sensor Drift" or "No Sensor Drift"

ShaftCondition — Condition of shaft, specified as "Shaft Wear" or "No Shaft Wear"

GearToothCondition — Condition of gear teeth, specified as "Tooth Fault" or "No Tooth Fault"

Read the transmission casing data from the CSV file "transmissionCasingData.csv" .

Convert the labels for prediction to categorical using the convertvars function.

View the first few rows of the table.

To train a network using categorical features, you must first convert the categorical features to numeric. First, convert the categorical predictors to categorical using the convertvars function by specifying a string array containing the names of all the categorical input variables. In this data set, there are two categorical features with names "SensorCondition" and "ShaftCondition" .

Loop over the categorical input variables. For each variable:

Convert the categorical values to one-hot encoded vectors using the onehotencode function.

Add the one-hot vectors to the table using the addvars function. Specify to insert the vectors after the column containing the corresponding categorical data.

Remove the corresponding column containing the categorical data.

Split the vectors into separate columns using the splitvars function.

View the first few rows of the table. Notice that the categorical predictors have been split into multiple columns with the categorical values as the variable names.

View the class names of the data set.

Split Data Set into Training and Validation Sets

Partition the data set into training, validation, and test partitions. Set aside 15% of the data for validation, and 15% for testing.

View the number of observations in the dataset.

Determine the number of observations for each partition.

Create an array of random indices corresponding to the observations and partition it using the partition sizes.

Partition the table of data into training, validation, and testing partitions using the indices.

Define Network Architecture

Define the network for classification.

Define a network with a feature input layer and specify the number of features. Also, configure the input layer to normalize the data using Z-score normalization. Next, include a fully connected layer with output size 50 followed by a batch normalization layer and a ReLU layer. For classification, specify another fully connected layer with output size corresponding to the number of classes, followed by a softmax layer.

Specify Training Options

Specify the training options.

Train the network using Adam.

Train using mini-batches of size 16.

Shuffle the data every epoch.

Monitor the network accuracy during training by specifying validation data.

Display the training progress in a plot and suppress the verbose command window output.

The software trains the network on the training data and calculates the accuracy on the validation data at regular intervals during training. The validation data is not used to update the network weights.

Train Network

Train the network using the architecture defined by layers , the training data, and the training options. By default, trainnet uses a GPU if one is available, otherwise, it uses a CPU. Training on a GPU requires Parallel Computing Toolbox™ and a supported GPU device. For information on supported devices, see GPU Computing Requirements (Parallel Computing Toolbox) . You can also specify the execution environment by using the ExecutionEnvironment name-value argument of trainingOptions .

The training progress plot shows the mini-batch loss and accuracy and the validation loss and accuracy. For more information on the training progress plot, see Monitor Deep Learning Training Progress .

learning matlab problem solving and numerical analysis through examples

Test Network

Predict the labels of the test data using the trained network and calculate the accuracy. Specify the same mini-batch size used for training.

Calculate the classification accuracy. The accuracy is the proportion of the labels that the network predicts correctly.

View the results in a confusion matrix.

learning matlab problem solving and numerical analysis through examples

trainnet | trainingOptions | dlnetwork | fullyConnectedLayer | Deep Network Designer | featureInputLayer

Related Examples

  • Create Simple Deep Learning Neural Network for Classification
  • Train Convolutional Neural Network for Regression
  • Deep Learning in MATLAB
  • List of Deep Learning Layers

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

  • América Latina (Español)
  • Canada (English)
  • United States (English)
  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)

Contact your local office

COMMENTS

  1. Numerical-Methods-with-Applications

    The instructions inside the live scripts will guide you through the exercises and activities. Get started with each live script by running it one section at a time. To stop running the script or a section midway (for example, when an animation is in progress), use the Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

  2. PDF Solving Applied Mathematical Problems with MATLAB

    Contents Preface xi 1 Computer Mathematics Languages — An Overview 1 1.1 Computer Solutions to Mathematics Problems . . . . . . . . 1 1.1.1 Why should we study computer mathematics language? 1

  3. PDF Numerical Analysis

    Chapter 1 Introduction to MATLAB 1-2 Numerical Analysis Using MATLAB and Spreadsheets, Second Edition Orchard Publications 2. Once the code is written and saved as an m-file, we may exit the Editor/Debugger window by clicking on Exit Editor/Debugger of the File menu, and MATLAB returns to the command win-dow. 3.

  4. Learning MATLAB: A Problem Solving Approach

    Learning MATLAB A Problem Solving Approach. ... A wealth of examples are completely discussed and solved, allowing students to learn Matlab by doing: by solving problems, comparing approaches and assessing the proposed solutions. ... Professor for numerical analysis and computer science at the University of Applied Sciences Neu-Technikum Buchs ...

  5. PDF Chapter 1

    What is Matlab? Matlab = Matrix laboratory Matlab is a problem-solving environment (PSE). PSEs are meant to allow the student / researcher to focus on the numerical analysis more than the details of computer programming. It was developed by Cleve Moler in the 1970s as a teaching tool. Today it is used almost everywhere, from universities

  6. Introduction to Numerical Analysis Using MATLAB

    ISBN: 978-1-934015-23-0; Language: English. Designed for courses in numerical analysis and as a reference for practicing engineers and scientists, this book presents the theoretical concepts of numerical analysis, and the practical justification of these methods are presented through computer examples using MATLAB. MATLAB is included as well as ...

  7. What Is Numerical Analysis?

    Numerical analysis is a branch of mathematics that solves continuous problems using numeric approximation. It involves designing methods that give approximate but accurate numeric solutions, which is useful in cases where the exact solution is impossible or prohibitively expensive to calculate. Numerical analysis also involves characterizing ...

  8. PDF Mathematics 3607

    that the way to learn MATLAB and numerical analysis is by doing it, not by reading about it. This course is taught in a computer lab and MATLAB will be used to some extent every class. Textbook: Learning MATLAB, Problem Solving, and Numerical Analysis through Examples, by Ed Overman (downloadable e-book). Topics List: 1.

  9. PDF Numerical Analysis Notes on Matlab

    Matlab Computing Notes Vectorization / Optimization MATLAB uses dynamic memory management (including garbage collection), and matrices are re-allocated as needed when new elements are added. It is however much better to pre-allocate space ahead of time using, for example, zeros. The colon notation is very important in accessing array sections, and

  10. PDF Numerical Methods with Worked Examples: Matlab Edition

    This book is a survey of the numerical methods that are common to undergraduate courses in Science, Computing, Engineering and Technology. The aim is to present sufficient methods to facilitate the numerical analysis of mathematical models likely to be encountered in practice. Examples of such models include the linear equations

  11. PDF Introduction to Numerical Methods and Matlab Programming for Engineers

    project was to make Matlab the universal language for computation on campus. That project was approved and implemented in the 2001-2002 academic year. In these lecture notes, instruction on using Matlab is dispersed through the material on numerical methods. In these lectures details about how to use Matlab are detailed (but not verbose) and ...

  12. PDF Math3607-BeginningScientificComputing Spring2012-13

    different types of problems, in many different technical areas, using MATLAB. The prob-lem solving will be drawn from many disciplines, including mathematics, physics, biology, and economics; it will be taken primarily from my soon-to-be book. This will improve your problem solving skills, and your MATLAB skills, and it might even be somewhat fun.

  13. Numerical Methods with Worked Examples: MATLAB Edition, 2e

    ISBN: 978-94-007-1365-9; Language: English. Numerical Methods with Worked Examples: MATLAB Edition is for students following an introductory course in numerical methods, numerical techniques, or numerical analysis. It introduces MATLAB as a computing environment for experimenting with numerical methods.

  14. PDF AMATLABTutorial

    ordinary di erential equations, mathematical modelling, and numerical analysis. It also includes an intro-duction to two- and three-dimensional graphics because graphics is often the preferred way to present the results of calculations. In this tutorial MATLAB is rst introduced as a calculator and then as a plotting package. Only af-

  15. Numerical Methods with Worked Examples: Matlab Edition

    He has taught extensively on courses involving numerical analysis and computer programming. He is an advocate of active learning and publishes pedagogic research papers in this area. His technical research has focussed on the numerical solution of integral and partial differential equations and parallel numerical algorithms.

  16. PDF Matlab Workbook

    This workbook aims to teach you Matlab and facilitate the successful integration of Matlab into the CME 102 (Ordinary Di erential Equations for Engineers) curriculum. The workbook comprises three main divisions; Matlab Basics, Matlab Programming and Numerical Methods for Solving ODEs. These divisions are further subdivided into sections, that ...

  17. PDF Mathematics 3607 3 credits Beginning Scientific Computing Au, Sp

    This course is taught in a computer lab and MATLAB will be used to some extent every class. Textbook: Learning MATLAB, Problem Solving, and Numerical Analysis through Examples, by Ed Overman (downloadable e-book). Topics List: 1. MATLAB as a scalar calculator, round-off errors, debugging. 2. Arrays in MATLAB, probability theory, Markov ...

  18. PDF Chapter 7 Numerical Methods in MATLAB

    MATLAB is one of the most suitable platforms to perform this iterative analysis. Using MATLAB, it is easier to perform a higher number of iterations more easily to reach the convergence. An example is given below where a set of equations are solved for determining the unknown variables using the Gauss-Seidel method. 7.2 Gauss-Seidel Method 141

  19. Learning MATLAB: A Problem Solving Approach

    Learning MATLAB: A Problem Solving Approach provides a comprehensive and stimulating introduction to MATLAB, a computer language now widely used for technical computing. Teaching and learning a substantial programming language are not always straightforward tasks. Accordingly, this textbook is not meant to cover the whole range of this high-performance technical programming environment ...

  20. PDF Engr M10: Programming and Problem-solving in Matlab

    Utilizes the MATLAB environment to provide students with a working knowledge of computer-based problem solving methods relevant to science and engineering. Introduces the fundamentals of procedural and object-oriented programming, numerical analysis, and data structures.

  21. Numerical Methods Using MATLAB, 4th edition

    The fourth edition of Numerical Methods Using MATLAB provides a clear introduction to a wide range of numerical methods that have practical applications. The authors' approach is to integrate MATLAB with numerical analysis in a way which adds clarity to the numerical analysis and develops familiarity with MATLAB. MATLAB graphics and numerical output are used extensively to clarify complex ...

  22. Train Network with Numeric Features

    To train a network using categorical features, you must first convert the categorical features to numeric. First, convert the categorical predictors to categorical using the convertvars function by specifying a string array containing the names of all the categorical input variables. In this data set, there are two categorical features with ...