Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
% 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

Réponse acceptée

Torsten
Torsten le 9 Fév 2023
Modifié(e) : Torsten le 9 Fév 2023
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

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by