Plotting and User Defined Function
Plotting and User Defined Function
Drawing a curve
a = [0:0.5:5];
b = 2*a.^2 + 3*a -5;
plot(a,b)
Refine the plot: Line pattern, color, and
thickness
a = [0:0.5:5];
b = 2*a.^2 + 3*a -5;
plot(a,b,'-
or','MarkerFaceColor','g','LineWidth',2)
xlabel('X'); ylabel('Y');
legend('Test','Location','NorthWest')
Line Style
mainprog1.m
for n = 1:5
x = n*0.1;
z = myfunc1(x);
fprintf('x = %4.2f f(x) = %8.4f \r', x, z)
end
• Output:
x = 0.10 f(x) = 7.3200
x = 0.20 f(x) = 7.6800
x = 0.30 f(x) = 8.0800
x = 0.40 f(x) = 8.5200
x = 0.50 f(x) = 9.0000
Formatting Operator