Plotting complicated function with asymptotes
显示 更早的评论
Hi,
I am struggling to plot this equation in Matlab
I have tried using plot, fplot and ezplot but none seem to be able to handle it. Would anyone be able to help me with this?
采纳的回答
Did you try
y = linspace(7, 12, 1000);
signal = exp(y .* cot(y)) .* sin(y);
plot(y, signal, 'b-', 'LineWidth', 2);
grid on;
xlabel('y');
ylabel('Signal');
6 个评论
Ben, are you still there? I haven't heard from you. What is this signal supposed to represent in the real world? Did my code work for you? I don't know what range you want to observe over - you did not say. Here is a full demo showing the plot over the 0 to 3*pi range.
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 18;
y = linspace(0, 3*pi, 1000);
signal = exp(y .* cot(y)) .* sin(y);
% signal = cot(y);
plot(y, signal, 'b-', 'LineWidth', 2);
grid on;
xlabel('y', 'FontSize', fontSize);
ylabel('Signal', 'FontSize', fontSize);
ylim([-1, 1.8]);
title('signal = exp(y .* cot(y)) .* sin(y)', 'FontSize', fontSize);

Is this what you wanted? Please let me know.
Hi,
Thanks for this. This unfortunately still shows the asymptotes, I am looking for a way to plot this without it showing the asymptotes as I need it to identify points of intersection with another function.
What part of the signal is NOT part of an asymptote? Can you mock up a graph for what you'd like it to look like so I can see what parts of the curve should be plotted and what parts should not be plotted?
By the way, to have it not plot some points, you can replace those points with NaN.
And are you going to answer my questions about what this equation describes, and the vertical and horizontal ranges over which you'd like to view it?
I am trying to recreate this figure. The solid line is the function in question.

y = linspace(0, 16, 2000);
signal = exp(y .* cot(y)) .* sin(y);
% Get rid of vertical "asymptotes" by setting anything outside our viewing range to nan.
nanIndexes = signal > 100;
signal(nanIndexes) = nan;
% Plot signal in solid black line.
plot(y, signal, 'k-', 'LineWidth', 2);
grid on;
xlabel('N', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
ylim([-10, 40]);
title('signal = exp(y .* cot(y)) .* sin(y)', 'FontSize', fontSize);
% Plot dashed line from (0, 0) to (7.5, 40);
hold on;
plot([0, 7.5], [0, 40], 'k--', 'LineWidth', 2);
% Plot dashed line from (0, 0) to (16, 15);
plot([0, 16], [0, 15], 'k--', 'LineWidth', 2);
% Make a black line along the x axis
yline(0, 'LineWidth', 2);

If that solves it, could you please "Accept this answer"? Thanks in advance.
Thankyou so much this is perfect!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
