Generating a matrix based on an equation with conditions

Hello,
Are there any way to do the following?
I want to generate a n*1 matrix based on this equation:
M = T1*G*Z1 - T2*G*Z2 + F - C*P
all variables are known and constant but with the following conditions:
1) F is zero in the entire column, excpet at a certain row, its equal to a constant number
2) From Row 1 to a certain row, this term (T2*G*Z2) is zero, for example until row 200. While from row 201 to the end, the previous term has constant value but this term (T1*G*Z1) is zero.
Thanks

6 commentaires

How can M be 1*n if F is a column vector?
A Aln
A Aln le 22 Mar 2019
Modifié(e) : A Aln le 22 Mar 2019
Sorry, M is the nx1 matrix:
[
1
2
3
4
5
.
.
n
]
and the numbers should be calculated based on this equation:
T1*G*Z1 - T2*G*Z2 + F - C*P
all of them are known, but based on the row, some of them will be zeros as mentioned in the above conditions.
the matrix should look like this
[
1
1
2 < in this row only, F = constant number
1 < till here, this term (T2*G*Z2) is zero and this term (T1*G*Z1) is constant number
3 < starting from here, this term (T1*G*Z1) is zero and this term (T2*G*Z2) is constant number
3
3
3
]
Sorry for the ambiguityHope it's clear now
Matt J
Matt J le 22 Mar 2019
Modifié(e) : Matt J le 22 Mar 2019
OK, but what then is the problem? If everything on the right hand side is known, then it should be straightforward to calculate M.
A Aln
A Aln le 22 Mar 2019
Modifié(e) : A Aln le 22 Mar 2019
Im new to the matlab, I don't know how to make the conditions, I tried to do that with if statement but it not works for matrices
If is most likely not needed.
What are the size of all the variables (T1, G, etc.)?
If they are not scalar variables did you mean * or .* for the multiplications?
A Aln
A Aln le 22 Mar 2019
Modifié(e) : A Aln le 22 Mar 2019
Yes I mean Multiplication, My problem is to make the conditions
if row 50 onward, change the value from 1 to 2
I can change single value by using this for example
A(5,1)=5;
But how can I change any number below this row

Connectez-vous pour commenter.

 Réponse acceptée

For example,
>> A=zeros(10,1); A(1:5)=4; A(6:10)=3
A =
4
4
4
4
4
3
3
3
3
3

1 commentaire

thank you so much, that what I did before, somehow horrible
r1 = (dH*grav*delz) - (accm*pi);
r2 = -(dB*grav*delz) - (accm*pi); %% The eqn
RR = zeros(x*y*z,1);
RR(1:x*y,1:1)=r1;
RR((x*y)+1:x*y*z,1:1)=r2;
RR(well,1)=RR(well,1)+q;
the variables are different and not defined here bcs its part of big code, Again I really appreciate your help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Functions dans Centre d'aide et File Exchange

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by