# HOW DO I DO THAT IN MATLAB SERIES?

In this series, I am answering questions that students have asked me about MATLAB. Most of the questions relate to a mathematical procedure.

## TOPIC

How do I solve a set of simultaneous linear equations given in equation form?

## SUMMARY

```% Language : Matlab 2008a;
% Authors : Autar Kaw;
% Mfile available at
% http://numericalmethods.eng.usf.edu/blog/sle_equations.m;
% Last Revised : August 22, 2009;
% Abstract: This program shows you how to solve a set of
%     simultaneous linear equations given in equation form?
%           .
clc
clear all
clf
```

## 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 K Kaw of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/sle_equations.m')
disp(' ')
disp('LAST REVISED')
disp('   August 22, 2009')
disp(' ')
```
```ABSTRACT
This program shows you how to solve a
set of simultaneous linear equations given in equation form

AUTHOR
Autar K Kaw of http://autarkaw.wordpress.com

MFILE SOURCE
http://numericalmethods.eng.usf.edu/blog/sle_equations.m

LAST REVISED
August 22, 2009

```

## INPUTS

Enter the equations

```eqn1='12*a+23*b+39*c=29'
eqn2='13*a+17*b+19*c=37'
eqn3='21*a+23*b+29*c=59'
```
```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)
```
```
INPUTS
________________________
Equations
________________________
12*a+23*b+39*c=29
13*a+17*b+19*c=37
21*a+23*b+29*c=59
```

## 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('________________________')
```
```
OUTPUTS
________________________
Solution Vector
________________________

Value of a= 2.95203
Value of b= 0.302583
Value of c= -0.343173
________________________
```