Creating linear equations in matlab

9 ビュー (過去 30 日間)
Aftab Ahmed Khan
Aftab Ahmed Khan 2016 年 2 月 20 日
コメント済み: Star Strider 2016 年 2 月 22 日
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

採用された回答

Star Strider
Star Strider 2016 年 2 月 20 日
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 件のコメント
Aftab Ahmed Khan
Aftab Ahmed Khan 2016 年 2 月 22 日
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 2016 年 2 月 22 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by