Matlab for loops involving matrix

Click For Summary
SUMMARY

This discussion focuses on implementing a for loop in MATLAB to solve a system of equations involving a variable parameter 'a'. The equations are 3x1 + ax2 = 1 and ax1 + 4x2 = 0, with 'a' varying from -π to π in increments of 0.2. Users are guided to utilize the RREF function for solving the equations and to plot the results for x1 and x2 against 'a', including a legend in the final plot. The discussion highlights the importance of correctly assigning the variable 'a' within the loop for effective computation.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with the RREF function in MATLAB
  • Basic knowledge of plotting functions in MATLAB
  • Concept of variable indexing in loops
NEXT STEPS
  • Learn how to implement the RREF function in MATLAB for solving linear equations
  • Explore MATLAB's plotting functions to visualize data effectively
  • Research variable assignment within loops in MATLAB
  • Study the use of the data cursor tool in MATLAB for extracting plot values
USEFUL FOR

Students, educators, and researchers in mathematics or engineering who are using MATLAB for solving systems of equations and visualizing results.

aplittle31
Messages
1
Reaction score
0
Given the following system of equations
3x1 + ax2 = 1
ax1 + 4x2 = 0

where -pi ≤ a ≤ pi. We would like to find out the range of values of x1 and x2 that are observed as a is varied. Do this as follows:

1. Create a for loop that uses the variable a as the indexing value, varied from over the
specified range in increments of 0.2.
2. For each value of a, solve the above system by using the RREF function.
3. Also for each value of a, plot the values of x1 and x2 against the corresponding value of a
for each loop iteration (i.e. the coordinate pairs (a,x1) and (a,x2)). Include a legend in
your final plot! See MATLAB help for more details.
4. From the plot, determine the range of values for x1 and x2. You may use the data cursor
tool to pick off values from the plot.

I understand and have completed step 1. However I don't know how to assign each new a to a variable that can be plugged into the matrix for step 2. Right now my for loop looks like:

i=0.2;
for a=-1*pi:i:pi,
a
end
 
Physics news on Phys.org

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 29 ·
Replies
29
Views
5K