Creating linear equations in matlab
16 views (last 30 days)
Aftab Ahmed Khan on 20 Feb 2016
How can i create 9 different equations in matlab if i have this general form of equations. I never did any thing of this kind before. I can enter these equations manually but i have very high number of equations (1000) so thats why i am looking for some method which can create it for me. In this case "n" is equal 2. Thank you so much
Star Strider on 20 Feb 2016
This is how I would build your matrix:
C = pi; % Assume A Value For ‘C’, A Scalar
n = 3; % Choose ‘n’
P = randi(99, n); % Create ‘P’
for j1 = 2:(n-1)
for j2 = 2:(n-1)
M(j1, j2) = C*P(j1, j2) - C * P(j1+1, j2) - C * P(j1, j2+1) - C * P(j1, j2-1);
j1 = n-1;
for j2 = 2:(n-1)
M(j1, j2) = C*P(j1, j2) - C * P(j1+1, j2) - C * P(j1, j2+1) - C * P(j1, j2-1) - C * P(j1, j2-1);
j1 = n;
j2 = n;
M(j1, j2) = C * P(j1, j2) - C * P(j1-1, j2) - C * P(j1, j2-1);
Note that MATLAB indices begin with 1 (all index references have to be positive integers), so it’s necessary to consider that in the code and make the appropriate changes. If you want to use this in a solver function of some sort, I would wrap the loops in a function and then use that function as the objective function of the solver. There may be more efficient ways to create your matrix, but I decided to just go with the description you provided.
You will likely have to experiment with this to get the result you want, but this should get you started.
While I’m thinking about it, let us know how your communications research goes, and attach PDFs of papers you publish from it, especially those that include MATLAB scripts or functions. Also, if you develop any MATLAB scripts that could be useful for others, document them thoroughly and submit them to the File Exchange.