Trouble superimposing two functions onto the same graph. One is correct, the other is incorrect.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% 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
0 Kommentare
Akzeptierte Antwort
Torsten
am 9 Feb. 2023
Bearbeitet: Torsten
am 9 Feb. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!