Author Topic: Some basic Octave GNU questions  (Read 1684 times)

0 Members and 1 Guest are viewing this topic.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 2545
  • Country: ca
Some basic Octave GNU questions
« on: October 10, 2026, 10:25:21 pm »
I'm beginner level friendly with Octave, and I had been solving time domain ODE's and systems of ODE's in spreadsheets before, but that's slow and tedious, with all the matrices and complex numbers. So I jumped back into Octave. And for now I'm not using the ODE solver lsode, I'm just automating some of how I solve them in spreadsheet.

Some questions are)

Say you had a system of ODE's, and you find a characteristic polynomial on paper and then in Octave solve it with the roots function, and say put the results in a column vector. And say you put that same system matrix into Octave, and find the eigen value roots with the "eig" function, and put them in a column.

Will the roots function, and the eig function, always put the roots in the same order ? And are complex roots always 1st ?

Also if you have a list or vector, etc, is there any easy way, or commands to easily separate the complex numbers from the solely real numbers in the list/vector/etc?

For a vector or list in general, is there a fast easy way to normalize it to say start with a leading 1, or what about find the largest number or say the closest to entry to 1, and then normalize that entry and the rest to that ?

When finding the basis vectors of a null space, say from homogeneous ODE's and eigenvalue problems like above with matrices (not in lsode). So using the "null" function on matrices from the above eigenvalue problems. Like below in a 3rd order system and I had 3 different, null space basis column vectors. Is there an easy way to normalize them, as if I had chosen 1 as the free parameter when finding the basis vectors?

And when I did it in the spread sheet, I choose z=1 each time as the free parameter, for all the 3rd row entries. So my results look a fair bit different. I hope there's no row swapping going on.

But either way it would be nice quickly normalize such vectors or rows/column's /lists, in this case I would make the 3 real entries near 1, I'd make them 1. I can imagine doing it with a bunch of steps, but is there some quick command or thing already built for it ?

n1 =

   0.9508 +      0i
   0.0483 + 0.2999i
   0.0059 + 0.0610i

n2 =

   0.9508 +      0i
   0.0483 - 0.2999i
   0.0059 - 0.0610i

n3 =

   0.020641
   0.101109
   0.994661

« Last Edit: October 10, 2026, 10:31:15 pm by MathWizard »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 5745
  • Country: Earth
Re: Some basic Octave GNU questions
« Reply #1 on: October 11, 2026, 02:18:31 pm »
I think these are several different implementation-related questions rather than Octave-specific questions.

Could you clarify what exactly you're trying to achieve and what isn't working as expected?
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 2545
  • Country: ca
Re: Some basic Octave GNU questions
« Reply #2 on: October 17, 2026, 06:31:19 am »
Well there probably is a quick way to sort real and complex numbers, but I haven't yet tried, what I found in the help file for that.

I'm just getting to grips with the computer code way of doing anything.
I was able to solve systems of ODE's in Octave w/o using the lsode. Just using my step by step eqns on paper.

But I couldn't get lsode to work with any of that.

So after a couple of days of head scratching, I figured out how to make anonymous functions and getting them working in other commands and anonymous functions.

Now I have lsode working, and yeah between State Space Modelling, and Octave to be the super calculator, and LTSpice to compare with...this is very powerful stuff I can't wait to use more of.


Quote
R=1; C=1; tau=R*C; x0=ones(4,1);    % initial state variables vc1,2,3,4 all set to 1V
Vso=[10; 5];    %Vsource1,2 amplitude
beta=[0.5*2*pi; 0.2*2*pi];    %Vsource1,2 frequency

Vs1 = @(t) ( Vso(1)*sin(beta(1)*t) );
Vs2 = @(t) ( Vso(2)*sin(beta(2)*t) );
u = @(t) [ Vs1(t); Vs2(t) ];    %input soucre vector

T= zeros(4,4); T(1,1)=T(1,3)=T(2,2)=T(2,3)=T(3,3)=T(4,4)=tau;
E= zeros(4,4); E(1,1)=E(2,2)=E(2,4)=E(3,3)=E(4,2)=E(4,4)=-1; E(3,1)=E(3,2)=1;
F = zeros(4,2); F(1,1)=F(2,2)=F(4,2)=1; F(3,2)=-1;
Tinv = inv(T);
A = Tinv*E;   %system matrix A
B = Tinv*F;   %source matrix B

x = zeros(4,1);   %state vector for vc1,2,3,4
xdot = @(x,t) ( A*x + B*u(t) );   %it's time derivative vector

t = linspace(0,10,1e4);
x = lsode(xdot, x0, t);
plot(t,x)
« Last Edit: October 17, 2026, 06:37:19 am by MathWizard »
 

Offline Slh

  • Regular Contributor
  • *
  • Posts: 199
  • Country: gb
Re: Some basic Octave GNU questions
« Reply #3 on: October 17, 2026, 06:48:47 am »
If it's something that uses commands that matlab has then you can see what the matlab documents say. Octave treats incompatibility with matlab as a bug so it should be the same (or a bug someone might sort it out eventually)
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 2545
  • Country: ca
Re: Some basic Octave GNU questions
« Reply #4 on: October 17, 2026, 06:59:06 am »
Yeah I've not used matlab, and it seems most people say they are very similar, but with some differences. So many more people use matlab, hopefully there are more explanations of stuff, that explain more about the code and how it's structured, and used.
 

Offline Sensorcat

  • Regular Contributor
  • *
  • Posts: 212
  • Country: de
  • Independent Sensor Consultant
    • Sensorberatung
Re: Some basic Octave GNU questions
« Reply #5 on: October 17, 2026, 10:34:23 pm »
Also if you have a list or vector, etc, is there any easy way, or commands to easily separate the complex numbers from the solely real numbers in the list/vector/etc?

You do pretty complex stuff with ODEs and I'm not sure if I understand your question completely, but separating real numbers from complex is supported like in this example:

Code: [Select]

octave:1> data = [1, 1+i, 2, 2*i];

octave:2> C = imag(data)~=0
C =

    0   1   0   1

octave:3> data(C)
ans =

    1 + 1i    0 + 2i


You can test for anything with a boolean expression to get a logical array (here: C) and filter with that array doing what Matlab calls 'logical indexing'.
 
The following users thanked this post: MathWizard


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->