I am trying to plot sin^2(x) together with cos^2(x) between [0,2pi]
but cant get my matlab to accept sin^2(x).
here is what I wrote, what am i doing wrong?
x=0:0.01:2*pi
si=sin^2(x);
co=cos^2(x);
plot(si,co)

댓글 수: 5

manoj pokhriyal
manoj pokhriyal 2020년 9월 4일
si=(sin(x))^.2
co=(cos(x))^.2
plot(si,co)
manoj pokhriyal
manoj pokhriyal 2020년 9월 4일
sorry my mistake
si=sin(x).^2
co=cos(x).^2
plot(si,co)
Hammad
Hammad 2024년 1월 23일
이동: Dyuman Joshi 2024년 1월 23일
how sin(-5) is equal to 0.9589 in matlab?
That is the correct value for the sine of -5 radians. If you wanted to compute the sine of -5 degrees use the sind function instead of the sin function.
R1 = -5; % radians
D1 = rad2deg(R1) % -5 radians in degrees
D1 = -286.4789
sineOfMinus5Radians = [sin(R1); sind(D1)]
sineOfMinus5Radians = 2×1
0.9589 0.9589
D2 = -5; % degrees
R2 = deg2rad(D2) % -5 degrees in radians
R2 = -0.0873
sineOfMinus5Degrees = [sind(D2); sin(R2)]
sineOfMinus5Degrees = 2×1
-0.0872 -0.0872
Dyuman Joshi
Dyuman Joshi 2024년 1월 23일
편집: Dyuman Joshi 2024년 1월 23일
@Hammad, the input of sin() is considered as radian, which can be seen from the documentation of sin (easily foundable by a simple search on the internet), thus the value is provided accordingly.
If you want to compute considering the input as degrees, use sind.
Also note that the output shown is a truncated value upto 4 digits after decimal, which is not what the actual value is.

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

 채택된 답변

David Hill
David Hill 2020년 9월 4일
편집: David Hill 2020년 9월 4일

3 개 추천

x=0:0.01:2*pi;
si=sin(x).^2;
co=cos(x).^2;
plot(x,si,x,co);
figure;
plot(si,co);%not sure which one you want

댓글 수: 4

Miri van de Kamp
Miri van de Kamp 2020년 9월 7일
thanks
sin(2*x);%sind(2*x) for x in degrees
@윤선 이, no worries, I teach you.
x = 0:0.01:pi;
y = sin(2*x);
plot(x, y)
An alternative to specifying the spacing is to specify the number of elements in the vector with linspace(), like
numElements = 2000; % Should be enough to fit all the way across your screen.
x = linspace(0, pi, numElements);
y = sin(2 * x);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('y');
title('Y vs X');
xlim([min(x), max(x)]);

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

추가 답변 (1개)

hemin ahmad
hemin ahmad 2024년 2월 18일

0 개 추천

sin(x)

댓글 수: 1

Walter Roberson
Walter Roberson 2024년 2월 18일
No, this is not correct. As explained above, sin(x).^2 is needed.

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2020년 9월 4일

댓글:

2024년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by