在本示例中,将给出如何用matlab绘制示意图,添加图例,添加标题等等,以及在matlab中调用LaTeX字体的命令。
代码如下:
clear;clc;close all
% Initialize symbolic variables
syms x f df
% example
disp('An Example, Plot Function and Derivative')
f = sin(x^2)
df = diff(sym(f));
pretty(df)
xx = linspace(-5,5);
x = xx;
fx = eval(f);
dfx = eval(df);
plot(xx,fx,'r-','LineWidth',2)
hold on
plot(xx,dfx,':b','LineWidth',2)
grid on
set(gca,'FontSize',12);
set(gca,'LineWidth',2);
set(gca,'TickDir','out');
xlabel('x','FontSize',20);
ylabel('$f(x)$, $\frac{df(x)}{dx}$','FontSize',20,'Interpreter','latex')
title(['$' latex(f) '$ and Derivative $' latex(df) '$'] ,'FontSize',30,'Interpreter','latex')
legend(...
'$f(x)$',['$\frac{df(x)}{dx}$=$' latex(df) '$'],...