[Scilab-users] Plot a function that contains matrix operations

Serge Steer Serge.Steer at inria.fr
Fri Nov 30 10:45:35 CET 2012


Here is a code that correspond to your wish:


initv = [1 0 0 0 0];
Smat = [-0.7 0.061984965 0 0.111572936 0.200831285;
         0 -1.4 0.5 0 0;
         0 0 -0.9 0 0;
         0 0.5 0 -1.4 0;
         0 0 0 0.5 -0.5];

onevec = [1 1 1 1 1];

S0vec = [0.325610814; 0.9; 0.9; 0.9; 0];

// Dichtefunktion :
function y=f(x)
   y=initv*expm(Smat*x)*S0vec
endfunction


scf(1); //create figure  1
clf(1); //clear figure 1
x= linspace(0,20,101);


plot(x,feval(x,f))

xlabel('x'); ylabel('f(x)')

title('Dichtefunktion von TBPS')


You can also write it as follow


// Dichtefunktion :
function y=f(x,init,A,vec)
   y=init*expm(A*x)*vec
endfunction
....
plot(x,feval(x,list(f,initv,Smat,S0vec))



Le 29/11/2012 17:55, Svenja Lagershausen a écrit :
>
> Dear users,
>
> I would like to plot a function f(x) that contains matrix operations.
> Correctly, it looks like this (obtained by Mathematica):
>
>
>
> Do you know how to do this?
>
> My code is:
>
> ///Löschen der Variablen/
>
> clear
>
> ///Bereinigen der Konsole/
>
> clc
>
> /// S. Lagershausen/
>
> /// 2//9.11.2012/
>
> /// System : M = 3, n = 3, Expo -  vtlte Bz., mu1 = 0.7, mu2 = 0.5, 
> mu3 = 0.9/
>
> /// E[TBPS] = 2.59664365/
>
> /// CV[TBPS] = 0.908682321/
>
> /// Daten der Verteilung der Zeit zw. Bearbeitungsbeginnzeitpunkten an 
> Station 1 :/
>
> initv= {1 0 0 0 0}
>
> Smat= [-0.7 0.061984965 0 0.111572936 0.200831285;
>
> 0-1.4 0.5 0 0;
>
> 00 -0.9 0 0;
>
> 00.5 0 -1.4 0;
>
> 00 0 0.5 -0.5]
>
> onevec= {1 1 1 1 1}
>
> S0vec= {0.325610814; 0.9; 0.9; 0.9; 0}
>
> /// Dichtefunktion :/
>
> _scf_(1);///create figure  1/
>
> _clf_(1);///clear figure 1/
>
> x=[1: 0.2 : 20]
>
> //x=2
>
> /////x= linspace(0,20,101);/
>
> ///temp1=Smat*x/
>
> ///f_x= sum(sum(Smat*x,"c"),"r")///
>
> ///test=Smat*(x);/
>
> f_x=initv*expm(Smat*x)*S0vec
>
> ///f_x=x/
>
> ////
>
> _plot_(x,f_x)
>
> /////xlabel('x'), ylabel('f(x)')/
>
> ///title('Dichtefunktion von TBPS')/
>
> ///Generating function of the PH renewal process/
>
> ///P_Stern=exp((Smat + z*S0vec*initv)*x)/
>
> x is the variable. If I simply plug in a single value, it works (the 
> result is a value)
>
> However, if I I declare a range, it does not work anymore 
> ("Inconsitent multiplication")
> I suppose that Scilab understands the range of x as a vector such that 
> the matrix operations cannot work that way.
>
> Thank you very much for your help!
>
> Best regards
> Svenja Lagershausen
>
> 	
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121130/a3a9f51a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 1337 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20121130/a3a9f51a/attachment.png>


More information about the users mailing list