/r/octave
Subreddit for discussing topics and questions related to GNU Octave.
Now back open for business!
GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. The Octave language is quite similar to Matlab so that most programs are easily portable.
/r/octave
Hi, I'm writing some Octave programs for a college project and I need to code a function that given a Matrix A, it makes an LU factorization with partial and full pivoting. Right now I have written the code for the Factorization with partial pivoting but I'm not able to make the code for the full pivoting. How could I adapt the code of my partial pivoting function to use full pivoting? Here's the code for the partial pivoting function:
function [L, U, P] = FactLUPC(A)
% Get the size of A
[m, n] = size(A);
% Initialize matrices
L = eye(m);
U = A;
P = eye(m);
for k = 1:min(m, n)
% Find the index of the pivot
[~, max_index] = max(abs(U(k:m, k)));
max_index = max_index + k - 1;
% Swap rows of U and P
if max_index != k
U([k, max_index], :) = U([max_index, k], :);
P([k, max_index], :) = P([max_index, k], :);
if k > 1
L([k, max_index], 1:k-1) = L([max_index, k], 1:k-1);
end
end
% Factorization
for j = k+1:m
L(j, k) = U(j, k) / U(k, k);
U(j, :) = U(j, :) - L(j, k) * U(k, :);
end
end
end
i want to know what is cause of this error in command window
and why is it showing file doesnt exist in terminal
I'm using gnu octave to generate audio. I tried to use the audioplayer function with 4 and 8-track arrays, but it doesn't play the audio on 4 or 8 output channels. Even in 9.2.0 this doesn't work. I cannot find any information about this problem. With mono or stereo arrays everything is fine. If you have experience with this problem, please tell me. I tried it on Mac OSX Ventura, but also on windows11 it doesn't play the four tracks. I have tested the settings of my 8-track audiocard the AUDIO-configuration (on mac) and I can play 4 or 8-track files with quicktime. In the documentation multitrack audio is explicitly mentioned:
Here is my script:
% Define audioproperties
samrat=44100;
bitrat=16;
% Create audio array
t=4; %seconds
tt=(1:(samrat*t))./samrat;
tone1=[sin(2*pi*200*tt) tt*0 tt*0 tt*0];
tone2=[tt*0 sin(2*pi*300*tt) tt*0 tt*0];
tone3=[tt*0 tt*0 sin(2*pi*400*tt) tt*0];
tone4=[tt*0 tt*0 tt*0 sin(2*pi*500*tt)];
toneA=[sin(2*pi*200*tt) tt*0];
toneB=[tt*0 sin(2*pi*400*tt)];
% This one work perfectly
toneout2=[toneA;toneB]';
% This one doesn't work.
toneout4=[tone1;tone2;tone3;tone4]';
% Call player
player = audioplayer (toneout4, samrat, bitrat);
play (player);
If you have an idea how to solve this problem or experience with this function your reactions are highly appreciated.
x=linspace(0,2.5,6)
y=-16*x^2+100
but the command window says error:for x^y,only square matrix arguments are permitted and one argument must be scalar. Use ^for elementwise power.
As an absolute newbie,I think there should be nothing wrong with it from a mathematical expression perspective.
a=-1.5;
b=-1;
f=@(x)sqrt(x+2)-2*cos(x);
tol=1e-3;
n=15;
format long
%Komentar
if f(a)*f(b)>=0
error("Los unos")
end
xTacno=fzero(f,[a,b]);
xMin=-1.6;
xMAx=-0,9;
X=linspace(xMin,xMax,1000);
Y=f(x);
plot(X,Y,'b');
hold on
plot(xTacno,0,'r',MarkerSize',5);
plot(a,0,'b.',MarkerSize',5)
plot(b,0,'b.',MarkerSize',5)
%fplot(f,[a,b])
plot([xMin,xMax],[0,0],'k');
xlim([xMin,xMax]);
grid on
for i=0:n
x=(a+b)/2;
plot(x,0,'y.','MarkerSize',5)
pause(1)
fprintf('%d:x=%.7f/n',i,x);
if abs(f(x))<tol
break
end
if f(a)*f(x)<0
b=x;
else
a=x;
end
xOld=x;
plot(xOld,0,'k','MarkerSIze',5)
end
hold off
I'm trying to run a code I found but this error is getting in the way, any tips?
this is the code I'm running:
% Program to form Admittance Bus Matrix
function ybus = ybus(); % Returns ybus
e = actxserver('Excel.Application'); % First, open an Excel Server.
eWorkbook = e.Workbooks.Add;
e.Visible = 1; % Insert a new workbook.
eSheets = e.ActiveWorkbook.Sheets; % Make the first sheet active.
eSheet1 = eSheets.get('Item', 1);
eSheet1.Activate;
A = ['PLEASE FILL THIS EXCEL SHEET WITH JUST THE VALUES IN THIS ORDER FROM RIGHT HERE- START FROM FIRST COLUMN FIRST ROW. DONT FORGET TO SAVE IT'];
B=['Column 1- From Bus number. Column 2- To Bus number. Column 3- Resistance(R). Column 4- Reactance(Z). Column 5- Group Admittance(Y/2)'];
eActivesheetRange = e.Activesheet.get('Range', 'A1');
eActivesheetRange.Value = A;
eActivesheetRange = e.Activesheet.get('Range', 'A2');
eActivesheetRange.Value = B;
%Displaying message
eWorkbook.SaveAs('E:\myfile.xlsx'); % Saving the file
clc;
fprintf('\n\t The data has been stored');
y=input('\n Press 1 to view Y Bus matrix for the above');
if(y==1)
linedata = xlsread('myfile'); % Calling linedata for Line Data
fb = linedata(:,1); % From bus number
tb = linedata(:,2); % To bus number
r = linedata(:,3); % Resistance, R
x = linedata(:,4); % Reactance, X...
b = linedata(:,5); % Shunt Admittance, B/2
z = r + i*x; % Z matrix
y = 1./z; % To get inverse of each element
b = i*b; % Make B imaginary
nbus = max(max(fb),max(tb)); % no. of buses
nbranch = length(fb); % no. of branches
ybus = zeros(nbus,nbus); % Initialise YBus
% Formation of the Off Diagonal Elements
for k=1:nbranch
if fb(k) > 0 & tb(k) > 0
ybus(fb(k),tb(k)) = ybus(fb(k),tb(k)) - y(k);
ybus(tb(k),fb(k)) = ybus(fb(k),tb(k));
end
end
% Formation of Matrix
for m=1:nbus
for n=1:nbranch
if fb(n) == m | tb(n) == m
ybus(m,m) = ybus(m,m) + y(n) + b(n);
else,
end
end
end
ybus; % Bus Admittance Matrix
end
Is it just me or is Octave on android wrong?
a few days ago I bought octave in the playstore my phone is an OppoA57 and when I try to open the application tells me error and exits the app, leaving the app insersible and a great feeling of helplessness because I use it for vector analysis classes.
How can I download octave on my compuradora, I try to do it on the official GNU page and it tells me that the connection is expired, nothing is downloaded, the screen appears as if there is no wifi even though there is.
Does anybody know whats going on here? All other tabs work, just the command window displaying spurious characters. Have been running old Octave 5.2 no issues, tried 9, then worked backwards to 6, still get this, but fine on 5? Am running Windows 7 with latest updates (no desire to use windows 10 with forced updates & restarts on a machine dedicated to running modelling & analysis 24/7)
Happy to announce the latest release (1.7.0) of the Statistics package for GNU Octave. See the release notes [here](https://github.com/gnu-octave/statistics/releases/tag/release-1.7.0).
I have written a program that basically does a fork load of math so I don't have to. Right now I am having it display each row of the matrix as it writes it with
disp(data(Row));
Is there a way to get it to display less information. I'd ideally just want
Construction_Angle = x
Construction_Line = y
I'm trying to plot a large red point on a plot using Octave. I can't figure out how to get the dot at the place indicated on the graph. When I try to plot the point it is always in the wrong spot. Can someone help me to be able to plot a solid red dot at any point on this graph? I've included my code below, and image 'IM.jpg'.
soils_triangle='IM.jpg';
hold ("on");
imshow (soils_triangle);
sandmin=65;
sandmax=457;
claymin=412;
claymax=26;
sand=(sandmax);
clay=(claymin);
plot (sand, clay, "ro", "markersize", 12, 'ydir', 'reverse');
hold ("off");
pause(4);
close all
I perform soil analyses, where I get percentages of clay and sand. I want to plot these values overtop of the Canadian Soils Triangle. Can someone please tell me how to do this?
In other words, I'd like to import the image below into a graph, and use the same axes as on the triangle in the image. From this point, I'd like to put a red dot where the values indicate.
Hey, anyone know how can i execute commands like "simpleFoam" in blueCFD for run an openFOAM simulation from octave?
For those of you who are investement sector focused and/ or (more experienced in Octave), how do you guys import stock data/ download web tabular data into GNU Octave? I have tried almost every single codes (including the most popular one Octave:##>>"......fecth_yahoo()....") I have come across without success. I have even tried tinkering with the code by using the "_yahoofinance" tag to try to comply with the new yahoo-finance api change. I am still get error from the interpretor. Recent warning is below:
">> fetchscndattempt error: 'fetch' undefined near line 26, column 12 The 'fetch' function belongs to the financial package from Octave Forge but has not yet been implemented. error: called from fetchscndattempt at line 26 column 10"
F.I.Y.
"pkg describe" confirms that financial pack is loaded.
Hope those of you with more experience can point me in the right direction/ to simple solution to this proble. Thanks in advance.
P/S Just for context, I am still a noob in programming in general and in the Octave/ Matlab Ecosystems. My best experience in programming comes from dabling in vba for excel. Played around a bit with in recent times with Python but its numerous libraries and their own problems gave me choices selection paralysis and other headaches to the point I was losing focus of my project. I dont have alot of free time per day and dont want to look focus of my main objectives and thus recently switched to Octave/ Matlab just for their simplicity (At least, it seemed, until this speed bump).
I've noticed that the movstd function swaps the dimensions of my matrix.
My input is Mdata_rs a 3x5x100 matrix and the output movSTDdata_rs is a 5x100x3 matrix. I tested with a smaller 3D matrices (2x3x5) and it works fine. Did I miss something in the documentation?
Here is my code :
clear; close all; clc;
xlist = 1:5;
ylist = (1:3)*10;
% Making a LUT from x and y : LUT --> nConf | x | y
count = 1;
for kx=1:length(xlist)
for ky=1:length(ylist)
LUT(count,:) = [count xlist(kx) ylist(ky)];
count = count+1;
end
end
% Making the data --> nConf | measurement
% data : 1 x1
% 2 x2
% ...
% 15 x15
% 1 x16
% 2 x17
% ...
Nrounds = 100;
data = zeros(Nrounds*length(LUT),2); % Let's have a multiple rounds/cycles measurements
data(:,2) = rand(length(data),1); % Random measurements
data(1:floor(Nrounds)*length(LUT),1) = repmat(LUT(:,1),[floor(Nrounds) 1]); % Fill the nConf column
% Parameter to compute a noise approximation
wlen = 3; % window length
opt = 0; %see movstd doc
%% Reshaping the data in a 3D matrix with each column in the third axis is a conf with Nrounds layers
Mdata_rs = reshape(data(:,2),[length(ylist) length(xlist) Nrounds]);
movSTDdata_rs = movstd(Mdata_rs,wlen,opt,3);
output1 = median(movSTDdata_rs,3); %Get a noise approximation ignoring the possible base line
It is such good software but the community seems dead. Not much activity relative to how good the software is, but there are always updates and many packages. Maybe users just don't need any help and therefore it's kind of quiet around it, and it just keep ticking by itself? What is the state of Octave?
I have constructed a MWE of what I don't understand
%MWE
flag = 1;
function sub = func1
fig1 = figure('Visible', 'off');
sub = subplot(1,1,1);
contour(magic(10));
end
function func2 (sub, flag)
fig2 = figure;
subplot(1,2,1)
copyobj(sub, fig2);
if flag
subplot(2,2,2)
end
end
sub = func1;
func2(sub, flag);
If I run this script, I get a blank figure--two pairs of axes but no plot. If I instead set the flag to zero, I see a contour plot (which is what I expect and need). Can anyone tell me why?
I am running a simulation that takes a while to complete and generates a contour plot (as a subplot of a larger figure). I then need to iterate many times to add a dot to that plot in a certain location. I could speed this up by a gigantic factor if I didn't need to regenerate the contour plot each time, so I have been trying (for the better part of a day now) to just import a handle to a subplot into another figure as a subplot.
FWIW, I can briefly see the plot I need if I switch to the figure window quickly enough. But it's erased when further subplots are created.
Hi,
I am a neuroscientist that recently joined a new lab. While we have a MATLAB license, we don't have license to any of the toolboxes I usually need (see list below). I thought about asking my lab leader to buy these toolboxes, which would cost about 2000 euros. But then I remembered that Octave is out there and several people have been talking positively about it recently. So I decided to have a look. I know that Octave is fairly compatible with MATLAB but not entirely. I assume that running MATLAB code in Octave might not produce identical results, I can live with that since I plan to code exclusively in Octave. How is the other way around? I tend to publish quite a bit of my code and functions, will Octave code produce exactly the same results in MATLAB or is it still an issue?
Finally, before I make the huge jump and try to transition several years of work to a new language I am wondering if I can find similar libraries to the following MATLAB toolboxes (because if I can't, Octave will probably not work for me):
Bioinformatics Toolbox 2) Curve Fitting Toolbox 3) Deep Learning Toolbox 4) Econometrics Toolbox 5) Image Processing Toolbox 6) Optimization Toolbox 7) Parallel Computing Toolbox 8) Signal Processing Toolbox 9) Statistics and Machine Learning Toolbox 10) Wavelet Toolbox.
I know that the best way is to try and see, but I would hate to spend 2-3 months of coding for a project until I hit a wall and have to migrate back.
I have encountered this problem when trying to install the control package on Octave. Any suggestions?
Since I installed octave, every time I try to open GUI I also get a CMD window. Any suggestions for it to open just GUI interface?
I am trying to convert an .m4a file to csv xy point so I can bring them in to a CAD software like fusion 360 and make it into a spline. I am brand new to Octave but what I saw it seemed like the right software to do it but I can't find anyone showing how to do it.. Any help would be great.
Also if you know a different way of doing this please let me know!
clc;clear;
A=5;
B=2;
C=12;
D=15;
dt=0.02;
t0=0;
yac=A;
tf=6;
it=0;
W=0.5;
yv = A - dt * B + (1/2) * (dt^2) * (-C*A - B*dyac) * (1/A);
for i=t0:dt:tf
yn = ((D*i*sin(3*i) - C*yac)*2 - (dt^2)*(2*A*yv) + (B*dt*yv) + 4*A*yac) * (1 / (2*A + B*dt));
it=it+1
vt(it)=i
vy(it)=yac
yv=yac
  yac=yn
  end
plot(vt,vy)
yn
I want to solve a problem of finding a point on a curve (which represents a river of a shape given by the curve) so that person can travel in minimum time from point A to point B which are located on different sides of a curve. The velocities of the person on the land and in the water are known and there is also the water current velocity. I tried to use fminbnd
function at first (1st image). My function looks like this:
function res = maliboo(fshore,Vr,x0,x1,Vb,Vw)
x = linspace(x0(1)-2, x1(1)+2);
y = fshore(x);
plot(x,y)
ylim([min(min(y), x1(2))-1 max(max(y), x0(1))+1])
hold on
plot(x0(1), x0(2), 'o')
plot(x1(1), x1(2), '*')
s1 = @(xx) sqrt((x0(1) - xx)^2 + (fshore(xx)-x0(2))^2);
s2 = @(xx) sqrt((x1(1) - xx)^2 + (fshore(xx)-x1(2))^2);
v2 = sqrt(Vr.^2+Vw.^2);
## t = s1 / Vb + s2 / v2;
t = @(xx) (sqrt((x0(1) - xx).^2 + (fshore(xx)-x0(2)).^2))./ Vb + (sqrt((x1(1) - xx).^2 + (fshore(xx)-x1(2)).^2))./ v2;
## xxx = fminbnd(t, x0(1), x1(1));
## h = @(xx) fshore(xx + (x1(1)-xx)/2) - (x1(2)-fshore(xx))/(x1(1)-xx) * (xx + (x1(1)-xx)/2) - fshore(xx)-((x1(2)-fshore(xx))/(x1(1)-xx))*xx;
xxx = sqp((x1(1)-x0(1))/2, t);
plot(xxx, fshore(xxx), 'x')
plot([x0(1) xxx], [x0(2) fshore(xxx)], '--', 'linewidth', 2)
plot([xxx x1(1)], [fshore(xxx) x1(2)], '--', 'linewidth', 2)
fshore is function handle that determines the boundary shape; Vr, Vb, Vw - speeds; x0, x1 - starting and ending points
The problem is that the second part of the path should be below the curve. I also tried to use sqp
function and the resulting point turned out a bit different (2nd image). I am not sure what condition should I add here to get the desired path. I wouldn't want to use any extra packages though...
Could someone please give a hint? Thanks in advance.
You want to create a 4-by-7 array of random numbers. Next your program moves through the array, element by element, and sets any value that is less than 0.2 to 0 and any value that is greater than (or equal to) 0.2 to 1.
Â
Your code looks like this, with one line missing (replaced by ???). What command belongs in that line?Â
A = rand(4,7);
[M,N] = size(A);
for j = 1:M
????????????????????
if A(j,k) < 0.2
A(j,k) = 0;
else
A(j,k) = 1;
endif
endfor
endfor
Hi,
I recently discovered that the group was unmoderated and became restricted (only approved users could post) for almost 2 years.
I requested to be moderator to get it going again.
I'm working through the queue slowly and I hope those who requested to join in the last two years might still be interested.
Let's say I have f(x)=x+y
and I want to integrate with respect to x
from 0-3
, which should give me 9/2+3y
. I can't seem to figure out how to do that though, any ideas? I tried this code,
function g = f(x)
g = x+y;
endfunction
[q, ier, nfun, err] = quad('f',0,3)
Which gives this error:
error: quad: evaluation of user-supplied function failed
error: called from
f at line 2 column 5
octave-test.m at line 4 column 21
I've written a short script that creates a cell array and adds a new cell for each csv file that I choose. The script keeps looping so I can keep choosing csv files. It stops when I push cancel in the file browsing window that pops up.
I'm seeing strange behavior with the ans variable. First off, I've put a semicolon after every line so I don't know why ans is created. Secondly, even if I type "clear ans" in the command line, ans is deleted and then immediately reappears. The value of ans is one of the csv files I browsed.
If I type "3+4" into the command line, it returns "ans = 7" and I can see that ans changes to 7 momentarily, but then ans right away changes to what it was before. I don't understand what could be causing ans to change.
Here's the script.
%% Data Loader v2
%
% Oct 7, 2022
% Choose Data Name in the save function below!
[fname, fpath] = uigetfile();
i = 1;
while fpath ~= 0
Test11_late{i} = csvread(strcat(fpath, fname));
i = i + 1;
[fname, fpath] = uigetfile();
end
clearvars -except Test11_early Test11_late;
% Set data name in the first argument below. Keep the quotes.
save(strcat("Test11", ".mat"));
Here's my workspace after running the script and choose two csv files.
https://i.imgur.com/EhgKm6P.png
​
I can probably work around this, but I'm really curious about what's going on. Any ideas are welcome! Thanks!
​
EDIT: Since ans was one of the csv files I chose, I wanted to see if it would change based on the order I chose the csv files and now I cannot get the behavior to happen. This issue was plaguing me yesterday, and today, and now that I've created this thread and changed the order I choose the csv files, I can't get it to do it at all anymore. Even when I go back to the original order I was choosing them.
I have no explanation.
I am not able to overcome this problem no matter what I try. I don't see anything wrong IM doing but yea I'm sure there is. Please help and thank you so much!
​
​
I've been stuck at this for 2 weeks and this is part of my research project. Please do explain in newbie language (if you're sharing the final codes that's fine too hehe)
Hello
I used octave in termux before but it doesn't work now. The old apks don't work, and the new app costs money. what other options are there?
Thanks for reading :)