MATLAB Answers

Hey please assist me with plotting this function, not sure why im getting indexing error

조회 수: 1(최근 30일)
Christopher Carey
Christopher Carey 23 Oct 2018
편집: gonzalo Mier 23 Oct 2018
here is my code
t=0:1:100
y1=(3/10)*(1-exp(-6*t)(cos(sqrt(14*t))+(((3*sqrt(14))/7)*sin(sqrt(14*t)))))
plot(y1,t)
Here is my error
Error: File: ap5_4.m Line: 2 Column: 14 ()-indexing must appear last in an index expression.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

답변(2개)

YT
YT 23 Oct 2018
편집: YT 23 Oct 2018
First off
% \/ you missed a * sign here
y1=(3/10)*(1-exp(-6*t)(cos(sqrt(14*t))+(((3*sqrt(14))/7)*sin(sqrt(14*t)))))
Secondly, because t1 is a vector, you should use element-wise multiplication `.*` instead of `*`. So y1 should be this:
y1=(3/10)*(1-exp(-6*t).*(cos(sqrt(14*t))+(((3*sqrt(14))/7)*sin(sqrt(14*t)))))
p.s.
Next time please format your code using the Code button

  댓글 수: 0

댓글을 달려면 로그인하십시오.


gonzalo Mier
gonzalo Mier 23 Oct 2018
편집: gonzalo Mier 23 Oct 2018
You are missing a multiplying symbol
y1=(3/10)*(1-exp(-6*t) [.*] (cos(sqrt(14*t))+(((3*sqrt(14))/7)*sin(sqrt(14*t)))))
So, use:
t=0:1:100
y1=(3/10)*(1-exp(-6*t).*(cos(sqrt(14*t))+(((3*sqrt(14))/7)*sin(sqrt(14*t)))))
plot(y1,t)

  댓글 수: 0

댓글을 달려면 로그인하십시오.


Translated by