フィルターのクリア

How can i plot this graph?

7 ビュー (過去 30 日間)
ak
ak 2019 年 12 月 3 日
コメント済み: ak 2019 年 12 月 3 日
I am trying to plot the graphs of y=-x mod 1 and y=-0.5*cos(2*pi*-x) mod 1. There are two issues here, for some reason there are points for eg x=0.25 where the y value should be 1 but instead theres a line between 0.25 to the next x value. Secondly MATLAB is plotting and straight line on x=0 for the line y=-x mod 1 which doesnt make sense. any help would be appreciated.
clear
clc
clf
syms x y
f1 = y == mod(-0.5*cos(2*pi*-x),1);
f2 = y == mod(-x,1);
%f3 = y == mod(-0.5*cos(2*pi*(-y)),1);
p1 = fimplicit(f1,[-0.5 1.8 0 1]);
hold on
p2 = fimplicit(f2,[-0.5 1.8 0 1]);
%p3= fimplicit(f3,[-2 2 0 1]);
hold off
fsize=15;
title('Intersection of curves','FontSize',fsize)
xlabel('x(t)','FontSize',fsize)
ylabel('y(t)','FontSize',fsize)
%s=vpasolve(mod(y+0.5*cos(2*pi*y),1),mod(x+y,1),[1.7,0.5]);
%s.x
%s.y
% End of Program 05a.

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 3 日
symbolic mod() does not mean what you think it means. When you pass an expression, it takes the mod of each subexpression, leaving any variables untouched, and drops the mod. For example, mod(5*x,3) is 2*x and not mod(2*x,3)
You have to replace your mod() operations with remainder operations such as
mod(A,B) --> A - floor(A/B)*B
(You might need a different expression for negative values of B)
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 3 日
syms x y
Mod = @(A,B) A - floor(A/B)*B;
f1 = y == Mod(-0.5*cos(2*pi*-x),1);
f2 = y == Mod(-x,1);
%f3 = y == mod(-0.5*cos(2*pi*(-y)),1);
p1 = fimplicit(f1,[-0.5 1.8 0 1]);
hold on
p2 = fimplicit(f2,[-0.5 1.8 0 1]);
%p3= fimplicit(f3,[-2 2 0 1]);
hold off
fsize=15;
title('Intersection of curves','FontSize',fsize)
xlabel('x(t)','FontSize',fsize)
ylabel('y(t)','FontSize',fsize)
This does not produce the same graph as before for me.
ak
ak 2019 年 12 月 3 日
Ah, I see what you meant now...
It worked!! Thank you so much. You are an absolute HERO

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

その他の回答 (1 件)

Marcel Kreuzberg
Marcel Kreuzberg 2019 年 12 月 3 日
clear
clc
clf
x = -0.5:0.001:1.8;
f2=mod(x,1);
f1=mod(-0.5*cos(2*pi*-x),1);
plot(x,f1,'.');
hold on
plot(x,f2,'.');
hold off
fsize=15;
title('Intersection of curves','FontSize',fsize)
xlabel('x(t)','FontSize',fsize)
ylabel('y(t)','FontSize',fsize)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by