## How do I solve simultaneous linear equations given in equation form? Updated Matlab 2018b

Guest co-blogger: : Luis Serrano

Many students ask me how do I do this or that in MATLAB.  So I thought why not have a small series of my next few blogs do that.  In this blog, I show you how to solve simultaneous linear equations given in equation form.

• The MATLAB program link is here.
• The HTML version of the MATLAB program is here.
• DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  DOWNLOAD THE MATLAB PROGRAM INSTEAD

%% SUMMARY
% Language : Matlab 2018b;
% Authors : Autar Kaw and Luis Serrano;
% Mfile available at
% http://nm.mathforcollege.com/blog/SimultaneousEquationsEqForm.m;
% Last Revised : January 22, 2020;
% Abstract: This program shows you how to solve a set of
% simultaneous linear equations given in equation form?
% .
clc
clear all
%% INTRODUCTION
disp(‘ABSTRACT’)
disp(‘ This program shows you how to solve a’)
disp(‘ set of simultaneous linear equations given in equation form’)
disp(‘ ‘)
disp(‘AUTHOR’)
disp(‘ Autar Kaw and Luis Serrano’)
disp(‘ ‘)
disp(‘MFILE SOURCE’)
disp(‘ http://nm.mathforcollege.com/blog/SimultaneousEquationsEqForm.m&#8217;)
disp(‘ ‘)
disp(‘LAST REVISED’)
disp(‘ January 22, 2020’)
disp(‘ ‘)
%% INPUTS
% Enter the equations
syms a b c
eqn1=12*a+23*b+39*c==29
eqn2=13*a+17*b+19*c==37
eqn3=21*a+23*b+29*c==59
%% DISPLAYING INPUTS
disp(‘ ‘)
disp(‘INPUTS’)
disp(‘________________________’)
disp(‘Equations’)
disp(‘________________________’)
disp(eqn1)
disp(eqn2)
disp(eqn3)
%% THE CODE
% The solution
X=solve(eqn1,eqn2,eqn3);
% Assigning the output
a=double(X.a);
b=double(X.b);
c=double(X.c);
%% DISPLAYING OUTPUTS
disp(‘ ‘)
disp(‘OUTPUTS’)
disp(‘________________________’)
disp(‘Solution Vector’)
disp(‘________________________’)
fprintf(‘\nValue of a= %g’,a)
fprintf(‘\nValue of b= %g’,b)
fprintf(‘\nValue of c= %g’,c)
disp(‘ ‘)
disp(‘________________________’)

_______________________

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## How do I solve a nonlinear equation that needs to be setup – Updated to MATLAB 2018b

Guest co-blogger: Luis Serrano

Many students ask me how do I do this or that in MATLAB. So I thought why not have a small series of my next few blogs do that. In this blog, I show you how to solve a nonlinear equation that needs to be set up.

For example to find the depth ‘x’ to which a ball is floating in water is based on the following cubic equation
4*R^3*S=3*x^2*(R-x/3)
where
S= specific gravity of ball
So how do we set this up if S and R are input values?

The MATLAB program link is here.

The HTML version of the MATLAB program is here.

• DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR.  DOWNLOAD THE MATLAB PROGRAM INSTEAD

%% SUMMARY
% Language : Matlab 2018b;
% Authors : Autar Kaw and Luis Serrano;
% Mfile available at
% http://nm.mathforcollege.com/blog/NonlinearEquations_withSetUp.m;
% Last Revised : January 22, 2020;
% Abstract: This program shows you how to solve a nonlinear equation
% that needs to set up as opposed that is just given to you.
clc
clear all
%% INTRODUCTION
disp(‘ABSTRACT’)
disp(‘ This program shows you how to solve’)
disp(‘ a nonlinear equation that needs to be setup’)
disp(‘ ‘)
disp(‘AUTHORS’)
disp(‘ Autar Kaw and Luis Serrano’)
disp(‘ ‘)
disp(‘MFILE SOURCE’)
disp(‘ http://nm.mathforcollege.com/blog/NonlinearEquations_withSetUp.m&#8217;)
disp(‘ ‘)
disp(‘LAST REVISED’)
disp(‘ January 22, 2020’)
disp(‘ ‘)
%% INPUTS
% Solve the nonlinear equation where you need to set up the equation
% For example to find the depth ‘x’ to which a ball is floating in water is based on the following
% cubic equation 4*R^3*S=3*x^2*(R-x/3) R= radius of ball S= specific gravity of ball So how do we set this up if S and R are input values
S=0.6
R=0.055
%% DISPLAYING INPUTS
disp(‘INPUTS’)
func=[‘ The equation to be solved is 4*R^3*S=3*x^2*(R-x/3)’];
disp(func)
disp(‘ ‘)
%% THE CODE
% Define x as a symbol
syms x
% Setting up the equation
C1=4*R^3*S
C2=3*x^2*(R-x/3)
f=C1==C2
% Finding the solution of the nonlinear equation
soln=vpasolve(f,x);
solnvalue=double(soln);
%% DISPLAYING OUTPUTS
disp(‘OUTPUTS’)
for i=1:1:length(solnvalue)
fprintf(‘\nThe solution# %g is %g’,i,solnvalue(i))
end
disp(‘ ‘)

________________________

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## Student participant costs in NSF budgets counts as direct cost

A common budget question gets asked about students who participate in the National Science Foundation Education and Human Resources NSF EHR grants and get paid for items such as focus group participation.  Does it count as direct cost?  Yes, it does.  Just read the language on page 53 (Page II-19) of Proposal & Award Policies & Procedures Guide (PAPPG) (NSF 19-1)

Human subject payments should be included on line G6 of the NSF budget under “Other Direct Costs,” and any applicable indirect costs should be calculated on the payments in accordance with the organization’s federally negotiated indirect cost rate.

## Third Edition of Programming Textbook

We have just published the third edition of the textbook on programming with MATLAB.   It is available for purchase at http://www.lulu.com/shop/autar-kaw-and-benjamin-rigsby-and-ismet-handzic-and-daniel-miller/introduction-to-programming-concepts-with-matlab-third-edition/paperback/product-24333322.html

The book is intended for an introductory course in programming in STEM (science, technology, engineering, and mathematics) fields while using MATLAB as the programming language. MATLAB is a popular computational software package used in universities and industries alike.

This textbook differentiates itself from others in two specific ways.

1. The textbook is suitable for the many engineering departments throughout the nation that no longer teach a 3-credit hour programming course. They weave programming and mathematical software packages such as MATLAB in courses such as Foundations of Engineering, Freshmen Design, Modeling of Systems, Engineering Analysis, Numerical Methods, etc. This book is highly suitable for such audiences. To achieve these goals and make the access far-reaching, we have been deliberate in keeping the lessons short in length so that instructors can easily choose the course content in a modular way.
2. The textbook is a stand-alone resource for learning programming where the lectures complement the textbook rather than vice versa. This is because of the reason above where in-classroom time is truncated, and therefore students need to be more self-taught. For this reason, we have been meticulous when selecting and organizing the textbook content to include fundamental and application programming problems that prepare students well for other problems they will solve in academia and industry.

The book has nine modules which have been each broken down by lessons. There are 42 lessons in all and depending on the learning outcomes of the course, an instructor can choose to assign only necessary lessons. Modules 1-3 focus on MATLAB and programming basics like the MATLAB program interface, programming variables, different types of data, debugging, plotting, and applications to science and engineering problems. In Module 4, we show the use of MATLAB for basic mathematical procedures learned in the engineering courses including nonlinear equations, integration, differentiation, simultaneous linear equations, interpolation, regression, and ordinary differential equations. In Modules 5-8, the user is introduced to basic programming concepts of conditional statements, repetition (loops), and custom functions. In Module 9, program input/output is shown with writing to and reading from external files as well as navigating directories with MATLAB. Important appendices include a primer on matrix algebra, a collection of mini-projects, and a introduction to animating plots in MATLAB. Appendix A provides a primer on matrix algebra. Appendix B contains a set of mini-projects. Appendix C demonstrates how to make animated plots in MATLAB.

Each lesson contains screenshots of actual MATLAB programs that are used to help illustrate the concepts presented. More than 120 complete programs are shown throughout this book to demonstrate to the reader how to use programming concepts. The book is written in a USA-Today style question-answer format for a quick grasp of the concepts.

The purpose of this book is to provide the reader with a firm basic understanding of MATLAB syntax and fundamental programming concepts. Each lesson contains MATLAB programs that are used to help illustrate the concepts presented. By no means do the authors claim to present every MATLAB command, function, application, or programming concept in existence.

## Time it takes to find a determinant

To make the point of how inefficient it is to find the determinant of a matrix by the cofactor method, I wrote a program in MATLAB to demonstrate this.  A google search for a program written in any language to find the determinant by using the cofactor method was not available beyond a 4×4 matrix.  So, I wrote one that finds the determinant of matrices of up to 12×12 order.

I ran the program on an Intel(R) Core(TM) i5-8500 CPU @3.00GHz PC.  Here is a table of the CPU time it took in seconds to find the determinant of a matrix as a function of its order.
______________________________________
Order of matrix               CPU Time to Find
Determinant (s)
______________________________________
6×6                                           0.015625
7×7                                           0.046875
8×8                                           0.203125
9×9                                           0.828125
10×10                                        5.14063
11×11                                       52.6406
12×12                                   623.953
______________________________________

If one continues to do this for a 25×25 matrix, it is estimated that it would take $8.1821198 \times 10^{17}$ seconds which is more than 25 billion years, and we all know that the estimated age of the universe is less at about 13.77 billion years.

The trend of the approximate time it takes to find the determinant of the next order of the matrix, nxn is approximately n times the time it takes to find the determinant of a (n-1)x(n-1) matrix.  For example, it took a time of 52.6406 seconds for finding the determinant of a 11×11 matrix, while it would be estimated to take approximately 12×52.6406=631.7 seconds for finding the determinant of a 12×12 matrix.  This is close to the 623.953 seconds it actually took.

The above approximate time calculations are in concurrence with the note written by Professor A.J. Wise in 1969, where he showed that the number of arithmetic operations required to evaluate a nxn determinant by cofactor method is given by [n!e]-2, and hence n!e for large n and the time it takes to find the determinant of the next order of the matrix, nxn is approximately n times the time it takes to find the determinant of a (n-1)x(n-1) matrix

Since the arithmetic operation required here are just addition, multiplication and subtraction, the computation time could be crudely estimated as 4Tn!e for large n, where T is the clock cycle time and we assume that an addition or a multiplication or a subtraction each use 4 clock cycle times.  Does it match?

For a 3.00 GHz machine, $T={1}/({3 \times 10^9})$ seconds to give an approximate time for a 12×12 matrix determinant calculation to be $4 \times {1}/{(3 \times 10^9)} \times 12! e = 1.736 seconds$.  It is not even of similar order.  Many items go into calculating CPU time for a numerical algorithm, but to do a comparative analysis, these calculations are quite helpful.

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## New site for the Numerical Method MOOC

Our MOOCs on Numerical Methods that were offered on canvas.net site have been moved to a new CANVAS Free for Teachers site.  Current students can continue to use the current MOOCs indefinitely.

For future students, the two-part MOOC now has been combined into one and it is accessible at any time.   There are no deadlines to start or finish.  To enroll, just click this link https://canvas.instructure.com/enroll/KYGTJR and you are on your way to learn Numerical Methods via audiovisual lectures, textbook content and online assessments.

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## Using Watu quizzes and Latex in WordPress

Many years ago, I modified a JavaScript code to develop online quizzes for Numerical Methods.  An example of that is here – right click to “View Page Source”. http://nm.mathforcollege.com/mcquizzes/01aae/quiz_01aae_introduction.html

The above quiz is adequate but looks vintage and I am currently in the process of migrating my whole numerical methods site to WordPress.  As part of this migration, I tried to update the JavaScript code to work on WordPress but that turned out to be above my pay grade.

After much searching, I found the WATU quiz plugin and am using it to redevelop the quizzes from scratch with much of the text being cut and paste from old quizzes.

WATU is quite versatile but I faced issues with rendering of the equations.  For that I use the WP-Katex plugin.  Simply put the equations between the  tagname latex in brackets []  followed by /latex in brackets [], and this shortcode works.  I would show an example to illustrate the use of the shortcode, but it gets rendered.  See usage here.

This use of latex shortcode worked well for the question statements in the quiz but when latex shortcode was put in the distractors, equations would show up with weird spacing.  This was resolved quickly by WATU support where they suggested to edit the WATU style.css file.  See https://wordpress.org/support/topic/latex-not-displaying-properly-in-multiple-choice-answers/ for the solution.  It worked.

Now, another Latex issue cropped up when a user would submit a quiz  and it shows the right answers to the user.  The equations written in Latex would not get rendered and instead it would show the linear form of the equations.   Those were resolved by going to general settings in the WATU quizzes and check marking quizzes to not use Ajax.

WATU is a complete solution for posting online quizzes on the web for student practice.  I am not using WATU to collect data or to assign a grade, but these capabilities do exist in WATU.

See the new version of the quiz I created now on WordPress: https://numericalmethods.autarkaw.com/quiz-chapter-01-01-introduction-to-numerical-methods-2/  Please do not bookmark the quiz as this is a test website and I will be migrating the test website to the original site (http://mathforcollege.com) by the time Fall semester starts.  This will create the least disruption to maintain legacy of open course ware.

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## Reducing ordinary differential equations to state variable matrix form

To be able to solve differential equations numerically, one has to reduce them to a set of first order ordinary differential equations – also called the state variable form.  By writing them in a matrix form, the equations become conducive for programming in languages such as MATLAB.  Here is an example of this reduction to state variable matrix form.

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at

## Synergistic Activities on NSF Proposals

The new 2019 NSF proposal guidelines effective February 25, 2019, have a change in how synergistic activities are reported. The change is described as follows.

Chapter II.C.2.f(i)(d), Synergistic Activities, has been revised to specify that a list should include up to five distinct examples that demonstrate the broader impact of the individual’s professional and scholarly activities that focuses on the integration and transfer of knowledge as well as its creation.”

The complete language is as follows.
“A list of up to five examples that demonstrate the broader impact of the individual’s professional and scholarly activities that focuses on the integration and transfer of knowledge as well as its creation. Examples could include, among others: innovations in teaching and training (e.g., development of curricular materials and pedagogical methods); contributions to the science of learning; development and/or refinement of research tools; computation methodologies and algorithms for problem-solving; development of databases to support research and education; broadening the participation of groups underrepresented in STEM; and service to the scientific and engineering community outside of the individual’s immediate organization.”

Well, for submission to an NSF grant due February 28, 2019, I revised my synergistic activities as follows. I want to know if this does or does not follow the guidelines. What would you change? I am having issues with the language of “list”, and “distinct”. Who can one contact at NSF for clarification? This does not seem to be a question for the program manager.

1. Conducted four workshops on engineering education internationally during a 2018 Fulbright Specialist program at Universiti Teknologi Petronas, Malaysia.  The four topics were flipped classrooms, the scholarship of teaching and learning, massive open online courses, and improving student performance through learning strategies.
2. Guest Editor, ASEE Advances in Engineering Education, Flipped Classrooms in STEM, 2016.  This special issue consisted of eight papers that showed how to implement and assess flipped classrooms in a variety of settings.
3. Developed, revised, assessed and refined holistic and customized web-based resources on Numerical Methods (http://numericalmethods.eng.usf.edu) and corresponding MOOCs on Numerical Methods and Introduction to Matrix Algebra.  The OCW receives 1,000,000+ annual page views, 2,000,000+ annual views of YouTube videos on NumericalMethodsGuy channel, 100,000+ annual views on Numerical Methods Guy blog.
4. Developed a unique textbook (adopted by 70 universities worldwide) and accompanying software PROMAL for undergraduates on the topic of Mechanics of Composite Materials published in 1997 (first edition) and 2005 (second edition) by CRC Press. This includes continued development of PROMAL – instructional software package for Mechanics of Composite Materials since 1985. More than 80 universities and many self-study students all over the world use PROMAL. The textbook has been translated to Persian and Turkish.
5. Designed open source software MCTestAnalysis for analyzing and refining multiple-choice tests based on the analytical framework developed by Jorion, et al (2016) used for the validity of concept inventories. The open source software includes results such as item difficulty, item discrimination, Cronbach alpha, model estimation, item characteristic curves, tetrachoric, and scree plots.

## Reporting results from prior NSF support when PIs on a proposal were PIs on a recent grant

Most NSF proposals limit you to 15 pages for proposal description, and most of us mortals have a hard time fully communicating our idea within the limit.  So one would like to minimize reporting prior NSF support that is not related to the proposal or count the same prior results description toward several investigators if they have previously worked together on an NSF grant.

The clarification brought here is for reporting results from prior NSF support. Read the requirements here — https://www.nsf.gov/pubs/policydocs/pappg18_1/pappg_2.jsp#IIC2diii

The purpose of this section is to assist reviewers in assessing the quality of prior work conducted with prior or current NSF funding. If any PI or co-PI identified on the proposal has received prior NSF support including:

• an award with an end date in the past five years; or
• any current funding, including any no-cost extensions,

information on the award is required for each PI and co-PI, regardless of whether the support was directly related to the proposal or not. In cases where the PI or any co-PI has received more than one award (excluding amendments to existing awards), they need only report on the one award that is most closely related to the proposal. Support means salary support, as well as any other funding awarded by NSF, including research, Graduate Research Fellowship, Major Research Instrumentation, conference, equipment, travel, and center awards, etc.

For a proposal recently submitted, I was working with four Co-PIs — let’s call them B, C, D, and E. I will call myself A.

We had worked on a directly related NSF grant in 2013–16 period for which A was the PI, and B and C were Co-PIs. On talking to a NSF official, writing prior-support results description for this grant would only count toward the reporting by one of the three investigators, A, B, or C. So let’s consider it to be counted toward Co-PI B. If PI A or Co-PI C have had other NSF grants as a PI or Co-PI which are current or have been active within the past five years, you will need to report one each for A and C (you cannot game the system if PI A or Co-PI C does not have another grant to report on, while Co-PI B does; each PI or Co-PI has to write prior support description on one grant each, unless a PI or Co-PI has none to report – for an award with an end date in the past five years or any current funding, including any no-cost extensions).

As per the NSF official, you cannot count the same prior-support description for more than one PI/Co-PI.

I got additional advice from my fellow investigator  — if you have an unrelated grant that you need to report under prior support guidelines, do so at the end of the proposal description under the heading of “Other Non-Related Prior NSF-Supported Projects”. Otherwise, it will unnecessarily distract the reviewer.