Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

For loop in matrix

3 visualizzazioni (ultimi 30 giorni)
sookyung Kang
sookyung Kang il 10 Lug 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
I'd like to create the matrix by two loops.
I tried to make the form below. Using "For loop"function, how can I make the code?
A=1;%dV/dx when x=1,A(0)=1
V=2;%V when x=1,V(0)=1
a=0; b=1;
n=100;
x=linspace(a,b,n);
h=x(n+1)-x(n);
V(i+1)=V(i)-A(i)-h.^2;% when i is from 0 to n
A(i+1)=A(i)+h;% when i is from 0 to n
plot(transpose(x),V,'r')

Risposte (1)

KSSV
KSSV il 10 Lug 2020
Modificato: KSSV il 10 Lug 2020
A=1;%dV/dx when x=1,A(0)=1
V=2;%V when x=1,V(0)=1
a=0; b=1;
n=100;
x=linspace(a,b,n);
h = x(2)-x(1) ;
V = zeros(size(x)) ;
A = zeros(size(x)) ;
for i = 1:n-1
V(i+1)=V(i)-A(i)-h.^2;% when i is from 0 to n
A(i+1)=A(i)+h;% when i is from 0 to n
end
plot(x,V,'r')
  4 Commenti
sookyung Kang
sookyung Kang il 11 Lug 2020
Oh it's good information ! thanks:) Then how can I use V(0)=2 and A(0)=1 as I got comments?
KSSV
KSSV il 11 Lug 2020
You cannot use it man.....instead use
V(1) = 2 ;
A(1) = 1 ;

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by