Categories

# Matlab Comet()

Comet is a function used to plot a graph in Matlab. Matlab plot function is also used to plot the graph but comet gives more efficient visualization as compared to the plot function. It is an animated graphical view of the input function. It contains two parameters head and tail. Head is a small circle which represents the start of graph and tail is a single line that traces the whole function. Comet function needs input parameters to operate the specific problem, where we can add various input options that are required in the graph. Comet function mostly used when input is also one of the functions which require some input from users.

## How does Comet() Works in Matlab?

There are various ways to write comet functions such as comet with a single parameter, a comet with two parameters, comet with three parameters including condition and comet with multiple parameters.

Steps to Use Comet() Function:

• Accept the input parameters
• Apply comet function (comet())
• Display the output

## Methods to Use Comet() Function in Matlab

Following are the methods to use Comet() function in detail.

## Syntax:

``comet (single parameter)``

Explanation: In the above example, there is only one parameter. Here we directly use-value of the parameter inside the brackets. otherwise, we can also declare any variable and then assign value 50 to the variable output of this example is only circle at value there will be two tracing of the tail. In table 1.2 first, we declare one variable ‘ip1’ then assign value to the variable ip1.output for this example is an only head position that is a circle, there will be no tracing of function. Table 1.3 shows the Matlab code for a range of values, in this input is ip1 which has values of 1 to 9, Output for this example is tracing of the tail from number one to number 9. And in table 1.4 input is cos function. In this example first, we declare the values of angles which are 1 to 10 and then we apply cos function on values 1 to 10 and then we apply comet function on cos. The output of this example is the tracing of cos function from value cos (1) to cos (10).

Table 1.1:

Following is the Output of table 1.1 single parameter with a direct value.

## Output:

Table 1.2:

The output of table 1.2 is as follows:

## Output:

Table 1.3:

The output of table 1.3 is:

## Output:

Table 1.4:

The output of table 1.4 Cos function with a range of values.

## Syntax:

``comet (first parameter, second parameter)``

Comet functions mostly used in this format only. In this type, there will be two parameters inside the comet bracket. These two parameters are the input of the function. In the first example table 2.1, we directly give the values to the function which are 40 and 30. The output of table 2.1 is only a head position that is a circle there is no tracing of function. In the second table 2.2 first, we declare the two variable ip1 and ip2 then we assign the values to the variables that means ip1 is 40 and ip2 is 30. The output of this example is only head position (ip1 with respect to ip2) which is a circle there is no tracing of function.

In table 2.3 input parameters are again function. Two functions cos and sin are used as input to the comet but cos and sin also require own input so input is given a range of values which is represented as an angle in this example. So the output graph is a trace of cos function with respect to trace of sin function.

Table 2.1:

The output of table 2.1:

## Output:

Table 2.2:

Output of table 2.2 two parameters with variables.

## Output:

Table 2.3:

The output of table 2.3: