Hello, can you help with this question, please?
I want to plot a function of y(theta) = sin(theta) , but matlab gives me error i don't know why.
I have tried this so far,
function [y] = myfunction(/theta)
y = sin(/theta)
end

 採用された回答

Stephen23
Stephen23 2020 年 5 月 11 日

0 投票

function [y] = myfunction(theta) % "/" is not valid in a variable name
y = sin(theta);
end

4 件のコメント

payam abubakr
payam abubakr 2020 年 5 月 11 日
Thank you! it worked well
but why it gives me errorr when I multiply it by cos(2 theta)?
y = sin(theta) * cos(2 theta);
appreciate your help!
payam abubakr
payam abubakr 2020 年 5 月 11 日
also, it does not allow me to plot it even with this code
y = sin(theta)*cos(2*theta)
Stephen23
Stephen23 2020 年 5 月 11 日
編集済み: Stephen23 2020 年 5 月 12 日
Like most programming languages, MATLAB does not have implicit multiplication of two things written next to each other: if two things are multiplied together, you need to write some multiplication operator between them.
This means your code is invalid because it is missing a multiplication operator:
cos(2 theta)?
% ^ missing!
Try this:
cos(2*theta)
"it does not allow me to plot it even with this code"
You need to learn about array and matrix operations:
y = sin(theta).*cos(2*theta);
% ^^ element-wise times
payam abubakr
payam abubakr 2020 年 5 月 11 日
thank you! it helped me a lot.

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

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 5 月 11 日

編集済み:

2020 年 5 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by