MATLAB [Matlab] Plotting a function inside a m-file?

AI Thread Summary
The discussion centers around a MATLAB script (A3.m) intended to plot the functions sin(2x) and its derivative, 2cos(2x). The user encountered issues with the plot not displaying correctly. The script includes commands for defining the x values, calculating y and z for the sine and cosine functions, and plotting them with appropriate titles and labels. Additionally, a separate function (f2.m) is defined to compute a polynomial expression. The user reported resolving the plotting issue with assistance from MATLAB Central, indicating that community support was instrumental in troubleshooting the problem.
tahayassen
Messages
269
Reaction score
1
A3.m:

%x = 0:pi/100:2*pi;
%y = sin(2*x);
%z = 2*cos(2*x);
%plot(x,y,'k',x,z,'--b')
%title('Plot of f(x)=sin(x) and it''s derivative')
%xlabel('X-axis')
%ylabel('Y-axis')
%legend('sin(2x)','2cos(2x)')
x = -2:0.01:2
y = f2(x)
plot(x,y)

f2.m:

function F = f2(x)
F(1) = 2*(x(1)^4)-3*(x(1)^2)+x(1)-7;

I ran A3.m but it doesn't seem to create a correct plot.
 
Physics news on Phys.org
Got my issue solved over at MATLAB central.
 

Similar threads

Replies
8
Views
2K
Replies
4
Views
1K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
1
Views
5K
Back
Top