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

Svenja Lagershausen lagershausen at prod.uni-hannover.de
Fri Nov 30 11:27:33 CET 2012


Dear Mathieu,

thank you very much. That solved it.
(Yes, x is a scalar).


Thank you Serge, as well!


- Svenja




-----Ursprüngliche Nachricht-----
Von: users-bounces at lists.scilab.org [mailto:users-bounces at lists.scilab.org] Im Auftrag von Mathieu Dubois
Gesendet: Donnerstag, 29. November 2012 23:31
An: International users mailing list for Scilab.
Betreff: Re: [Scilab-users] Plot a function that contains matrix operations

Hello,

I don't know what you want to model exactly but there are several problems in your code.

In scilab, if x is a vector, Smat*x means matrix multiplication. As Smat is a 5x5 matrix it certainly won't work with a 96 components vector.
If x is a scalar it is the scalar multiplication  (better written x*Smat).
The expression initv*expm(x*Smat)*S0vec (for a scalar x) works. Is that what you want to compute?

If you want to plot a function you should have a look at the fplot function.

You will find attached a simple script that produce a graph very similar to the one you send.

HTH,
Mathieu

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
>


More information about the users mailing list