Matrixes must agree error

조회 수: 3 (최근 30일)
Serena Simpson
Serena Simpson 2020년 10월 13일
답변: Bandar 2020년 10월 13일
I have the .* to do element by element math, however, it keeps coming back with matricies must agree errors
%% Section 1: Initalization of Variables
f = [0, 5, 10, 20]; %frequencies
t = 0:0.1:pi; %numbers for time
v =-5+exp(-5.*t).*((4.*cos(f.*t))+9.*sin(f.*t)); %equation %% Error here
%% Section 2: Processing
%applying the array f to each voltage
v1 = [v, f(1)];
v2 = [v, f(2)];
v3 = [v, f(3)];
v4 = [v, f(4)];
%% Section 3: Result Output
plot(v1, v2, v3, v4)
title('Voltage in a RLC circuit')
xlabel('Frequncy')
ylabel('Volts')

답변 (1개)

Bandar
Bandar 2020년 10월 13일
If you would like to carry out element-by-element mutliplication, vectors must have same size. In your case f has 4 elements whereas t has 32 elements.

카테고리

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