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?

 Respuesta aceptada

Image Analyst
Image Analyst el 28 de Feb. de 2021
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 comentarios

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.
Ben Phelps
Ben Phelps el 1 de Mzo. de 2021
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.
Image Analyst
Image Analyst el 1 de Mzo. de 2021
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?
Ben Phelps
Ben Phelps el 1 de Mzo. de 2021
I am trying to recreate this figure. The solid line is the function in question.
Image Analyst
Image Analyst el 1 de Mzo. de 2021
Editada: Image Analyst el 1 de Mzo. de 2021
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.
Ben Phelps
Ben Phelps el 1 de Mzo. de 2021
Thankyou so much this is perfect!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 28 de Feb. de 2021

Comentada:

el 1 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by