Creating linear equations in matlab

6 views (last 30 days)
Hello,
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

Accepted Answer

Star Strider
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);
end
end
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);
end
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.
  4 Comments
Aftab Ahmed Khan
Aftab Ahmed Khan on 22 Feb 2016
Ok thank you. Here is my first paper. I will also send you my second paper which is under review. I really appreciate your help.
Star Strider
Star Strider on 22 Feb 2016
As always, my pleasure.
Thank you. I saved it and will look at it later. It’s far from my areas of expertise, so I’ll definitely learn from it.

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!