필터 지우기
필터 지우기

Trying to multiply Matrices

조회 수: 1 (최근 30일)
Mark Prentice
Mark Prentice 2021년 8월 7일
답변: Walter Roberson 2021년 8월 8일
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에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by