Storing values of multiple vectors into one 1:100 matrix?

4 views (last 30 days)
v1=50
v3=75
i2=zeros(1, 100)
for v2=1:100
b=[v1; v2; v3]
y=L\b
x=U\y
end
I am using LU decomposition for the equation Ax=b to solve for the current (x=[i1; i2; i3]) when the voltage (b) is v1=50, v3=75, and every value of v2 from 1 to 100. I already have all the values in the 3x3 matrix for resistance values (A). I need to save all the values of i2 that correspond to the changing v2 values and save them all into a 1x100 matrix.

Answers (1)

Matt J
Matt J on 23 Jan 2018
for v2=1:100
b=[v1; v2; v3]
y=L\b
x=U\y
i2(v2)=x(2);
end
  3 Comments
Shawna Myatt
Shawna Myatt on 19 Oct 2018
I have a question about this bit of code that you posted. I am new to MatLab, so I was able to follow all of it up until the last line. Why did you use i2(v2) = x(2) to get an output of all of the i2 solutions? I can see where the i2 and the v2 come from, but how does the x(2) fit in?
I want to make sure that I am understanding the concepts behind this. Thanks!
Matt J
Matt J on 20 Oct 2018
Edited: Matt J on 20 Oct 2018
The 3x1 vector x is the solution to A*x=b and x(2) extracts the second element of x.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!