I am facing problem with big fraction

3 ビュー (過去 30 日間)
Muhammad Usman
Muhammad Usman 2019 年 10 月 6 日
コメント済み: Walter Roberson 2019 年 10 月 6 日
Hello everyone,
When i am writing the following code, "sumx" returns me value in fraction, i want to show my result in terms of "pi". Need some help
n=3;
k=1;
for S=1:n
if k==n
sumx=pi/2;
else
sumx = pi/2+(2/pi)*((((-1).^k(1,:))-1).*cos(k(1,:)*x)./(k(1,:).^2));
plot(x,sumx,'r-')
end
end
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 6 日
What do you expect your values to look like? Are you expecting a vector something like
(35184372088832*pi^2 - 219978174876521)/(70368744177664*pi),
(281474976710656*pi^2 - 1766249117313443)/(562949953421312*pi)
Did you notice that your k does not change in the loop, and so k==n is either always true (if n happens to be 1, which it is not) or else always false (if n happens to be different from 1, which is the case.)
Did you notice that your statements in the loop do not depend upon S?
Did you notice that "plot on" is not set so you are plotting the same thing every time?
Did you notice that k is a scalar, but you are indexing it as if it were a row vector or 2D array ?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by