I am new to coding and am unsure why my code does not work it says "Unexpected MATLAB expression" for the 3 in my code.
This is my code E(x)= [-1 1] 3 . * exp (1) . ^ ((-x)./4)
Any help is appreciated

4 件のコメント

Jose Marques
Jose Marques 2017 年 9 月 11 日
Should be something between [-1 1] and 3.* ? What this represents?
Jose Marques
Jose Marques 2017 年 9 月 11 日
Maybe it is better to explain what the expression means.
Natalie Brehaut
Natalie Brehaut 2017 年 9 月 11 日
it is supposed to be an envelope to another function, I have tried to add .* in between but that comes up as unexpected MATLAB Operator
Natalie Brehaut
Natalie Brehaut 2017 年 9 月 11 日
I am supposed to code the function E(x)= plus or minus 3e^(-x/4)

サインインしてコメントする。

 採用された回答

Jose Marques
Jose Marques 2017 年 9 月 11 日

0 投票

Natalie, try this:
E= [-1 1] * 3 *( exp (1) .^ ((-x)/4))
E will be a matrix 1x2 that first element is positive value and second will be the negative value

7 件のコメント

Natalie Brehaut
Natalie Brehaut 2017 年 9 月 11 日
When that is put in it says that the Matrix dimensions must agree
Jose Marques
Jose Marques 2017 年 9 月 11 日
Are you using the matrix E after that? Post you intire code; thus, we can be helpfull
Natalie Brehaut
Natalie Brehaut 2017 年 9 月 11 日
編集済み: Natalie Brehaut 2017 年 9 月 11 日
Trial>> x= 1: 0.1 : 10; Trial>> y= 3 . * exp (1) .^ ((-x)/4) . * sin (2 . * x) y= 3 . * exp (1) .^ ((-x)/4) . * sin (2 . * x) ↑ Error: Unexpected MATLAB operator.
Trial>> E= [-1 1] * 3 *( exp (1) .^ ((-x)/4)) Error using * Inner matrix dimensions must agree.
I am just very lost in what is wrong with my codes
Jose Marques
Jose Marques 2017 年 9 月 11 日
A tip: you must use .* to element wise multiplication: https://www.mathworks.com/help/matlab/ref/times.html
Jose Marques
Jose Marques 2017 年 9 月 11 日
Natalie, have you ever use the for loop? Do you just wanna two values for E?
x=1:0.1:10;
for i=1:size(x,2)
y(i) = 3 * exp (1) .^ ((-x(i))/4) * sin (2 * x(i));
E= [-1 1] * 3 *( exp (1) .^ ((-x(i))/4));
end
plot(y)
Natalie Brehaut
Natalie Brehaut 2017 年 9 月 11 日
THAT WORKED THANK YOU SO MUCH
Jose Marques
Jose Marques 2017 年 9 月 11 日
Nice work!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Language Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by