@[TOC](matlab y=sin(x) - 2/π*(x)函数绘制)
y=sin(x) - 2/π*(x)
clc;
clear;
close all;
x_axis_length = 10;
y_axis_length = 10;
% 创建 x 值向量
x_positive = linspace(0.1, 10, 1000); % 正半轴上的 x 值
x_negative = linspace(-10, -0.1, 1000); % 负半轴上的 x 值% 计算正半轴和负半轴上的 y 值
y_positive = sin(x_positive) - 2./pi*x_positive;
y_negative = sin(x_negative) - 2./pi*x_negative;% 绘制图像
figure;
plot(x_positive, y_positive, 'b', 'LineWidth', 1.5);
hold on;
plot(x_negative, y_negative, 'r', 'LineWidth', 1.5);
xlabel('x');
ylabel('y');
title('Plot of y = sin(x) - 2/π*(x)');
legend('Positive Half-axis', 'Negative Half-axis');
grid on;% 设置 x 轴和 y 轴的范围
xlim([-x_axis_length, x_axis_length]);
ylim([-y_axis_length, y_axis_length]); % 显示坐标轴 x 轴和 y 轴