Filter löschen
Filter löschen

Trying to multiply Matrices

1 Ansicht (letzte 30 Tage)
Mark Prentice
Mark Prentice am 7 Aug. 2021
Beantwortet: Walter Roberson am 8 Aug. 2021
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Aug. 2021
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)

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by