two functions with descriptions in one graph

1 次查看(过去 30 天)
for this code:
% approximating f
plot(X_in.', U.');
xlabel('x');
ylabel('approximate f(x)');
legend_strs = compose('Approximate f with h=%.2d', h);
legend(legend_strs);
I get the followin graph (for two different axis steps h = [0.2, 0.025]):
What I want is to add another function to the same graph (true function f) and to add a description of the line in the above right section saying "true function f".
say that f = cos(2x)
how can I do this?
Thank you.

采纳的回答

Walter Roberson
Walter Roberson 2020-11-28
f = @(x) cos(2*x);
plot(X_in.', U.', X_in.', f(X_in.'));
xlabel('x');
ylabel('approximate f(x)');
legend_strs = [compose('Approximate f with h=%.2d', h), "true function f"];
legend(legend_strs);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by