Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Christopher Carey
Christopher Carey 2018 年 10 月 23 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (2 件)

YT
YT 2018 年 10 月 23 日
編集済み: YT 2018 年 10 月 23 日
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

gonzalo Mier
gonzalo Mier 2018 年 10 月 23 日
編集済み: gonzalo Mier 2018 年 10 月 23 日
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)

Community Treasure Hunt

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

Start Hunting!

Translated by