create a vector with a variable as an element

User Forumcreate a vector with a variable as an element
laurafish asked 3 years ago

Hi

I want to create a vector called "gss" with m but got the following:

m=-ln(0.5/0.24212945-1);
gss={m,1};

m
-0.062985214

gss[1,1]
+DEN

Why is that gss[1,1] is not equal to m? Plus why can't I just do gss={m}?

Thanks for your help!

Laura

1 Answers
aptech Staff answered 3 years ago

The reason that gss[1,1] is not equal to the value of m (-0.06298) is because GAUSS allows you to add character elements to matrices and vectors. So what you actually added to gss was the character element m. You can see this by printing it as a character element by prepending with the $ like this:

m=-ln(0.5/0.24212945-1);
gss={m,1};

print $gss[1,1];

results in:

   m

Depending upon what else is going on in the program you could do something like this:

//the pipe operator '|' performs vertical concatenation
gss = -ln(0.5/0.24212945-1)|1;

//or this
gss = ones(2,1);
gss[1,1] = -ln(0.5/0.24212945-1);