Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SciLab Plotting

How would you plot these in SciLab or MatLab? I am new to these and have no idea how the software works. Please help.

$Plot following functions with different colors in Scilab or MatLab
–   f2(x) = logn
–   f3(x) = n
–   f4(x) = nlogn
–   f5(x) = n2
–   f6(x) = nj (j > 2)
–   f7(x) = cn (c > 1)
–   f8(x) = n!

where x = linspace(1, 50, 50).
like image 413
h3tr1ck Avatar asked Sep 09 '26 20:09

h3tr1ck


2 Answers

Well, a lot of these are built-in functions. For example

>> x = linspace(1,50,50);
>> plot(x,log(x))
>> plot(x,x)
>> plot(x,x.*log(x))
>> plot(x,x.^2)

I don't know what nj (j > 2) and cn (c > 1) are supposed to mean.

For the last one, you should look at the function factorial.

It's not clear from the context whether you're supposed to plot them on different graphs or all on the same graph. If all on the same graph, then you can use

>> hold on;

to freeze the current axes - that means that any new lines will get drawn on top of the old ones, instead of being drawn on a fresh set of axes.

In Matlab (and probably in Scilab) you can supply a "line spec" argument to the plot function, which tells it what color and style to draw the line in. For example,

>> figure
>> hold on
>> plot(x,log(x),'b')
>> plot(x,x/10,'r')
>> plot(x,x.^2/1000,'g')

Tells Matlab to plot the function f(x)=log(x) in blue, f(x)=x/10 in red and f(x)=x^2/1000 in green, which results in this plot:

enter image description here

like image 71
Chris Taylor Avatar answered Sep 12 '26 17:09

Chris Taylor


I can't comment or upvote yet but I'd add to Chris Taylor's answer that in Scilab the hold on and hold off convention isn't used. All plot commands output to the current axes, which are 'held on' all the time. If you want to generate a new figure or change the current axes you can use figure(n), where n can be any (nonconsecutive) positive integer - just a label really.

See also clf(n), gcf() and gca() - Scilab's figure handling differs quite a bit from Matlab's, though the matplotlib ATOMS module goes some way towards making Scilab look and behave more like Matlab.

like image 25
xenoclast Avatar answered Sep 12 '26 17:09

xenoclast



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!