How to plot same function several times

15 ビュー (過去 30 日間)
Mayowa
Mayowa 2015 年 1 月 30 日
編集済み: Stephen23 2024 年 11 月 19 日 10:28
I will like to plot a function several times in a single plot
consider I have
angle = 0 b= 5; c = b + sin (angle); d= b + cos (angle); plot (c, d)
My aim is to plot c against d using angle 0, 30, 45, 60 and 90. And I want it in a single plot.
Thanks

回答 (1 件)

Raghava S N
Raghava S N 2024 年 11 月 19 日 8:40
Hello, @Mayowa,
As I understand, you want to plot the variable “c” against “d” for multiple values of the variable “angle” in the same plot.
This can be achieved by declaring the variable “angle” as a row or column matrix with the required values. This is because the “plot” function can take a matrix as input. For more information about how the “plot” function works, refer to this link - https://www.mathworks.com/help/matlab/ref/plot.html#mw_6748a9ec-33eb-483b-b8f1-919954dfae40:~:text=x%2Dcoordinates%2C%20specified%20as%20a%20scalar%2C%20vector%2C%20or%20matrix.
I have provided a sample code snippet to demonstrate the required functionality-
angle = [0 30 45 60 90];
b = 5;
c = b + sin (angle);
d = b + cos (angle);
plot (c, d)
Hope this helps!
  1 件のコメント
Stephen23
Stephen23 2024 年 11 月 19 日 10:16
編集済み: Stephen23 2024 年 11 月 19 日 10:28
Note that SIN, COS etc specify their input in radians, as their documentation clearly states.
Angle values of 30, 45, 60, and 90 usually indicate angles in degrees.
For angles in degrees the functions SIND, COSD, etc should be used:
a = [0,30,45,60,90];
b = 5;
c = b + sind(a);
d = b + cosd(a);
plot(c,d)
"This is because the “plot” function can take a matrix as input."
The code shown in this answer calls PLOT with vectors as inputs.

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by