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

Click For Summary
SUMMARY

The discussion focuses on plotting functions in MATLAB using m-files, specifically addressing issues encountered in the script A3.m. The user attempts to plot the function defined in f2.m, which computes a polynomial expression. The problem was resolved with assistance from MATLAB Central, indicating that the plotting command may have required adjustments to properly visualize the output of the function.

PREREQUISITES
  • Familiarity with MATLAB scripting and m-files
  • Understanding of function definitions in MATLAB
  • Knowledge of plotting functions using MATLAB's plot command
  • Basic grasp of polynomial functions and their graphical representation
NEXT STEPS
  • Explore MATLAB's plotting functions and customization options
  • Learn about debugging techniques for MATLAB scripts
  • Investigate function handles in MATLAB for more complex plotting
  • Study polynomial function behavior and visualization in MATLAB
USEFUL FOR

MATLAB users, data analysts, and engineers looking to enhance their skills in function plotting and script debugging within the MATLAB environment.

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 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K