MATLAB Matlab for loops involving matrix

AI Thread Summary
The discussion focuses on solving a system of equations in MATLAB using a for loop to vary the parameter 'a' from -π to π in increments of 0.2. Users are instructed to use the RREF function to solve the equations for each value of 'a' and to plot the resulting values of x1 and x2 against 'a'. A participant has successfully completed the loop setup but is unsure how to assign the current value of 'a' to a variable for use in the matrix calculations. The thread highlights the importance of MATLAB documentation for guidance on matrix operations. The objective is to visualize the ranges of x1 and x2 as 'a' changes.
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
Back
Top