フィルターのクリア

Trouble superimposing two functions onto the same graph. One is correct, the other is incorrect.

1 回表示 (過去 30 日間)
% I am trying to plot the functions y1 and y2. Both functions should start at 0,1. Whenever I graph it though, the % y1 starts properly, whereas the y2 starts below the x axis. I'm not sure why, and any help would be appreciated
% Y1 is the original function
% Y2 is the derivativef of Y1
%% Define x variables
x = linspace(0,pi,200);
%% calculate y values
y1 = atanCos1(x); %function (can be found below)
y2 = d_atanCos1(x);%function (can be found below)
%% Part C: plot the atanCos1 and d_atanCos1 curve
figure
hold on
plot(x,y1,'b-')
plot(x,y2,'g-')
%% FUNCTIONS WRITTEN BELOW written in seprate .m files
--------------------------
function[y1] = atanCos1(x)
y1 = (atan(x).*cos(x)) + 1;
end
--------------------------
function[y2] = d_atanCos1(x)
y2 = cos(x)/(x.^2 + 1) - atan(x).*sin(x);
end
%% here is the graph below

採用された回答

Torsten
Torsten 2023 年 2 月 9 日
編集済み: Torsten 2023 年 2 月 9 日
y2 = cos(x)./(x.^2 + 1) - atan(x).*sin(x);
instead of
y2 = cos(x)/(x.^2 + 1) - atan(x).*sin(x);
%% Define x variables
x = linspace(0,pi,200);
%% calculate y values
y1 = atanCos1(x); %function (can be found below)
y2 = d_atanCos1(x);%function (can be found below)
%% Part C: plot the atanCos1 and d_atanCos1 curve
hold on
plot(x,y1,'b-')
plot(x,y2,'g-')
hold off
grid on
function [y1] = atanCos1(x)
y1 = (atan(x).*cos(x)) + 1;
end
function [y2] = d_atanCos1(x)
y2 = cos(x)./(x.^2 + 1) - atan(x).*sin(x);
end

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by