Multiple Iterations over a system of linear equations
Show older comments
Hello all. I am trying to solve the system of linear equations define by CX = K over multiple iterations (300*delta_t). But my plot only plots the first time step. Can someone help me with understanding how I can fix this in my code below?
Thanks so much!
clear all
close all
clc
N=5;
u(1:1:N) = 0;
u(N+1) = 1;
delta_t = 20;
Below is the for loop im having trouble with
for t = 1:delta_t:300*delta_t
G(t) = t/20;
A(t) = G(t)/2;
B(t) = 1 + G(t);
for j = 2:1:N
k(j) = ((1-G(t))*u(j))+((G(t)/2)*(u(j+1)+u(j-1)));
end
C = [A(t) B(t) 0 0;
A(t) B(t) A(t) 0;
0 A(t) B(t) A(t);
0 0 A(t) B(t)];
k = [k(2); k(3); k(4); k(5)-A(t)];
X = C\k;
x1 = [0; X; 1];
y = 0:1/5:1;
plot(x1,y)
end
1 Comment
Ameer Hamza
on 17 Oct 2020
Can you write down your problem in mathematical form?
Accepted Answer
More Answers (1)
Rafael Hernandez-Walls
on 17 Oct 2020
I think the problem is where the plot function, maybe you need to put another command to plot in each iteration, something like this:
...
plot(x1,y)
drawnow
end
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!