Creating linear equations in matlab

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

 Respuesta aceptada

Star Strider
Star Strider el 20 de Feb. de 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 comentarios

Aftab Ahmed Khan
Aftab Ahmed Khan el 20 de Feb. de 2016
Editada: Aftab Ahmed Khan el 20 de Feb. de 2016
Hello, I don't have the probability values (P). Thats what i want to calculate for my 2-D markov chain. I want to make 9 different linear equations like this using above general form of equation.
Once i get to this, i want to make a diagonal dominant coefficient matrix like this.
Regarding my research, i have just started Markov Analysis for 5G Dual-hop Backhaul Networks in ultra-high capacity cells. Btw, where you want me to attach my PDF.
Star Strider
Star Strider el 20 de Feb. de 2016
With respect to the matrix, bear in mind MATLAB’s indexing conventions, so ‘P(1,0)’ would have to be ‘P(2,1)’. If you need to use the indices to calculate, just subtract 1 from them in your code. Build your matrix like I built the one in your Question. I would use the Optimization Toolbox fsolve function to solve it, so consider how it wants its objective functions coded, and write a function file with your matrix calculations as your objective function. If you want to estimate the ‘P’ matrix, you would have to enter it as a 9-element vector, so for instance if ‘Pv’ is that vector, ‘Pv(1)=P(1,1)’ ... ‘Pv(9)=P(3,3)’, then map it appropriately in your function. If you want to constrain the optimsation function so that the probabilities are bounded (0,1), consider using fmincon or one of the other Optimization Toolbox functions that allow constraints.
You lost me on the second matrix. It’s sparse by definition, so the sparse matrix functions would likely be appropriate to work with it.
If you have functions related to your paper that you want to upload to the File Exchange, be sure to attach it there. Especially if it relates to this Question or another Question, attach it here or to all that are appropriate. (I’d like to add your papers to my publication library) By attaching the paper, you don’t have to then explain in detail the context of your Question.
Aftab Ahmed Khan
Aftab Ahmed Khan el 22 de Feb. de 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 el 22 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Feb. de 2016

Comentada:

el 22 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by