There is a definite function solved in the trademark. It is necessary to build a graph, and place points on it only in places where the value is integer, not fractional.

If anyone is interested in specifics, the function looks like:

y = abs((cos(n).^sin(m-3)) + log(sqrt(2)+ 0.2*n + m^2.4) - 3 - (n+2)/(m-3.2)) 

where n = (-20:0.1:20) , and m = 16

Plotted y(n)

Since the step is 0.1, then in the plotted graph we have a lot of fractional values. If, for example, to execute the command plot(n,y,':B',n,y,'SM') , then all the values ​​of n are simply indicated by dots.

That is the question: how to make it so that only integer values ​​are marked?

  • clear; clc n = (- 20: 0.1: 20); m = 16; y = @ (n) abs (((cos (n)). ^ (sin (m-3))) + (log ((sqrt (2)) + (0.2 * n) + (m ^ 2.4))) -3 - ((n + 2) / (m-3.2))); n1 = round (n); plot (n, y (n), 'b', n1, y (n1), '+ r', 'LineWidth', 2) grid is the correct and simple solution to my problem :) - neo32
  • simple and incorrect, why he answered in the comments to his answer - aknew

2 answers 2

The simplest solution to the forehead is to simply count the function again for n1 = -20: 20 (only integer values) and build it. Or select only integer values ​​and construct them, if I am not mistaken, something like this:

 intN = isinteger(n); % массив булевных значений является ли n(i) целым n1 = n(intN); y1 = y(intN); 

But you need to check - I do not have a matlab at hand to check the correctness of the decision. Minus the second solution - if you somehow make a step, for example, 0.3, then the graph will skip many integers (although the question is whether you have a discrete function or not). Is it possible to make the raft somehow somehow only highlight the whole ones - I don't know

  • Thank you, I don’t know if this is correct, but I decided to just make u = round (n), that is, I just declared a new variable that corresponds to integer values ​​in the vector n - neo32
  • exactly wrong, this option will spawn extra points, for example, if n = [0 0.25, 0.5 0.75 1], then the final value may well be [0 0 1 1 1] - aknew
 plot(round (n),y,':B',n,y,'SM') 
  • 6
    You should not just give answers with code. Try to explain in your own words what your code does. - neluzhin
  • 3
    Please write more detailed answers. Complete your answer with an explanation of the code or describe your actions. - Yuri