Trying to multiply Matrices

1 次查看(过去 30 天)
Hey there,
I'm trying to pultiple some matricies to output a new matrix or array of Y but seem to be getting an error. "Array indices must be positive integers or logical values." I only need values at 4 evenly spaced interior points but cant seem to tell the equation to only look at 4 values instead of all 199. Anything help thank you.
close all;
clear all;
clear;
L=10; %given
EI=1900; %given
q=-0.6; %given
dx=0.05;%desired grid spacing
N = 1+L/dx
X = linspace(0,10,N)';
Y=X*0;%inital condistion
for n = 1 : length(X)-2 % the # of interrior points
%this creates B bar which is all known at every time step
B_bar(n,:) = (((q.*X(n).*(X(n)-L))*(dx^2))/(EI*2))
A=gallery('tridiag' , 4 , 1,-2,1)
Y(i)=A'.*B_bar

采纳的回答

Walter Roberson
Walter Roberson 2021-8-8
L=10; %given
EI=1900; %given
q=-0.6; %given
dx=0.05;%desired grid spacing
N = 1+L/dx
N = 201
X = linspace(0,10,N)';
Y=X*0;%inital condistion
for n = 1 : length(X)-2 % the # of interrior points
%this creates B bar which is all known at every time step
B_bar(n,:) = (((q.*X(n).*(X(n)-L))*(dx^2))/(EI*2))
A=gallery('tridiag' , 4 , 1,-2,1)
class(i)
whos i
disp(i)
Y(i)=A'.*B_bar
end
B_bar = 0
A =
(1,1) -2 (2,1) 1 (1,2) 1 (2,2) -2 (3,2) 1 (2,3) 1 (3,3) -2 (4,3) 1 (3,4) 1 (4,4) -2
ans = 'double'
0.0000 + 1.0000i
Array indices must be positive integers or logical values.
You are storing into Y(i) but i has value complex(0,1) .
You did not assign a value to i, so it has its default value, which is sqrt(-1) . The default value of j is also sqrt(-1)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by