フィルターのクリア

Trouble plottiing a trig function

4 ビュー (過去 30 日間)
Snow
Snow 2022 年 11 月 18 日
コメント済み: Image Analyst 2022 年 11 月 19 日
I want to plot the function sin^3(x)/((1-cos(x))^5) for values of x=[:pi].
So first I declared x = [0:.01:pi]
Then I try creating y.
When I set y = sin(x).^3 I do get a continous plot.
But when I start really tring to build the function for y, where y = sin^3(x)/((1-cos(x)).^5) i just get one single value when I do
plot(x,y).
Why is it all of a sudden giving me single value when I suddenl introduce the denominator?

採用された回答

John D'Errico
John D'Errico 2022 年 11 月 18 日
編集済み: John D'Errico 2022 年 11 月 18 日
Ok. You knew you had to use the .^ operator to raise the elements to a power, element-wise. There are also .* and ./ operators, for the same reason. Use them.
And then, we see you still did not even take your own advice, even though you said you knew how to raise sin(x) to a power. You still wrote the wrong expression.
y = sin(x).^3./((1-cos(x)).^5)
__ _
Note the two differences in what I wrote.
You should also learn to use linspace, NOT the colon operator for this. Why?
x = [0:.01:pi];
Look at the final element of x. Is it pi? No. In fact, it is wrong by a fair amount, that in some problems will be significant.
pi - x(end)
ans =
0.00159265358979299
However, if you do this:
x = linspace(0,pi,100);
pi - x(end)
ans =
0
Now it hits the endpoint exactly.
  3 件のコメント
John D'Errico
John D'Errico 2022 年 11 月 18 日
Then don't forget also the .* operator. No need to worry about addition and subtraction though. No dots there.
Image Analyst
Image Analyst 2022 年 11 月 19 日
@Anthony Ramirez If John's advice worked, please click the "Accept this answer" link to award John "reputation points". Thanks in advance. 🙂

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by