The dimension of my vector changes after a few iterations, how am I writing things incorrectly?

2 次查看(过去 30 天)
Hello,
Essentially, I am solving a system of linear equations, where Ax=b and A is a numerical scheme, x is a vector in the next time step, and b is the vector that used from the previous time step. I have n points in time, and m points in space (m=total number of points-1)
A doesn't change with each calculation, but it is a mxm matrix My first B is a m by 1 vector with all the points equal 300^1000 My first w is solved by A\b
So I wrote a few loops to now use w from iteration 1 as a B for iteration 2, and then get a w of iteration 2, and so on and so forth. The problem is 1) my matrix randomly grows from 99x1 to 100x1 in a few iterations
2) I am not getting an answer, so I am calculating my B incorrectly
So here's the code. q is used to save a vector after a certain number of iterations as a .csv file to be plotted later
q=0;
WOUT=zeros(m,1);% counter to enite data to csv file
for j=2:n-1,
q=q+1;
for p=2:m-1,
% this says take the w of the previous itr, multiply the %coefficients to in the previous, current, and future point in %space to eventually build a vector B. This vector should be used %to solve w for the next iteration
BB(j)=(c4.*w(p-1))+(c5(p).*w(p))-(c6.*w(p+1));
size(BB)
BB;
xp=x';
end
w=AA\BB;
%%loop to output every 10th solution in time
if q==10 %change this to any number
w1=w./1000; %convert to L
WOUT=[WOUT,w1];
q=0;
end
end
toc
csvwrite('k',WOUT)
end
Any additional suggestions and input is welcomed. Everyone here has been great about answering my questions. Thank you!

回答(1 个)

Jan
Jan 2012-4-24
I neither find "A" nor "B". Do you mean "AA" and "BB"?
What do you expect this line to do: BB;?
xp is calculated, but never used. There is even no x except for this line xp=x';.
Does your question mean, that BB grows from [99x1] to [100x1]? If so, j must be 100, what would be a consequence of n beeing 101 or larger.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by