Toma
Toma

Reputation: 171

scilab plotting of a function and datasets on the same graph

I am trying to display 3 curves of both measurements and theory on the same graph for comparison, using scilab. The problem is that while 2 curves have the same size for their datasets, the theoretical curve should be made from a function with a much larger dataset although both have the same range.

D1 and D2 have 13 values to be displayed with the 13 values for the x axis in D0 (tiks should range from 0 to 500). The theoretical function should be displayed along something like a linspace from 0 to 500 with 500 values and not only 13. Such that all the curves are aligned with tiks from o to 500 on the x axis.

I tried using the code shown below but it will only display the curves of D1 and D2.

My code:

clc;
clear;
xdel(winsid());
    D0 = [0, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, 480]; 
//x axis for D1 and D2
    D1 =[4.96, 5, 4.96, 4.96, 4.96, 4.96, 4.96, 4.96, 4.95, 4.96, 4.96, 4.96, 4.96];  //first curve
    D2 =[0, 1.61, 2.73, 3.58, 4.05, 4.24, 4.56, 4.72, 4.93, 4.88, 4.90, 4.90, 4.95];  //second curve
    foo1 = (-5)*(1-%e^((-1)/(0.1)*(linspace(0, 1, 500))));                            //the problematic function that will not show on the plot when the other curves are displayed
scf();
  aa = gca();
  aa.font_size=3;
  aa.thickness=2;
  plot(D0, D1, "r-", "fontsize",5);
  plot(D0, D2, "g-", "fontsize",5);
  plot(linspace(0, 1, 500), foo1);

I want the 3 curves to be on the same graph with x axis of 0 to 500.

Upvotes: 0

Views: 217

Answers (1)

user5694329
user5694329

Reputation: 412

You made an error for the linspace function you should use something like

   linspace(0, 500, 1000);

First point, last point, number of values.

Upvotes: 1

Related Questions