Defining a variable in specific nodes

Hi,
I need to define a variable B(j)) in the 1/2 3/2 5/2.... . e.g i have the variables A(i) and B(j). So the loops are( for i =2:N and j=2:N) .
And B(j)=A(i+1)-A(i)

8 件のコメント

Adam Danz
Adam Danz 2019 年 5 月 6 日
編集済み: Adam Danz 2019 年 5 月 6 日
" I need to define a variable B(j)) in the 1/2 3/2 5/2.... "
I don't understand.
Try to explain again.
m m
m m 2019 年 5 月 6 日
I am trying to calculate the potentiel A(i), after that i want to calculate the electric field B(j) whitch related with the potentiel by :
B(j)=(A(i+1)-A(i) )/dx.
Knowing that j=i+12
So if i use this relation B(j)=(A(i+1)-A(i) )/dx. How can i inmplement this in matlab??
Adam Danz
Adam Danz 2019 年 5 月 6 日
"I am trying to calculate the potentiel A(i)"
I don't know what this means.
"after that i want to calculate the electric field B(j) whitch related with the potentiel by : B(j)=(A(i+1)-A(i) )/dx Knowing that j=i+12"
Something along these lines, perhaps?
for i = __ : __ % ???
for j = 1:12
B(j) = (A(i+1)-A(i) )/dx
end
end
This can probably be written without for-loops but the concept is still unclear to me.
m m
m m 2019 年 5 月 6 日
N=10;
for i = 2 : N-1%
for j = ___:___ ??
B(j) = (A(i+1)-A(i) )/dx
end
end
the loop for j starts from what in this case?
Adam Danz
Adam Danz 2019 年 5 月 6 日
編集済み: Adam Danz 2019 年 5 月 6 日
Then the j-loop might be
for j = i:i=12
end
Im basing this off of your info "Knowing that j=i+12"
Or perhaps you don't need a 2nd loop if j is always equal to i+12. This might be the case!
m m
m m 2019 年 5 月 6 日
i'm sorry j=i+1/2 (not j=i+12)
Adam Danz
Adam Danz 2019 年 5 月 6 日
Well then I'm not sure what's going on because loops require integer increments.
m m
m m 2019 年 5 月 6 日
thank you

回答 (0 件)

この質問は閉じられています。

質問済み:

m m
2019 年 5 月 6 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by