octave ode program produces an unexplained error - octave

Have a file called f.m which has the following:
function xdot = f (x,t)
xdot = -exp(-t)*x^2;
endfunction
x=lsode("f",2,(t=linspace(0,5,50)'));
plot(t,x)
Running in octave 4.2.2 or 4.2.1 produces the following error:
error: 't' undefined near line 2 column 14
error: called from
f at line 2 column 6

Related

Octave doesn't allow me to read correctly

I am trying to read 5x^2 but octave says that it's wrong also it allows us to put (sin(x/2))^3
clc; close all; clear;
pkg load symbolic;
syms x;
f=input("Introduce la funcion ");
diff(f,x)
also there is the output with both cases
case (sin(x/2))^3
Introduce la funcion (sin(x/2))^3
ans = (sym)
2/x\ /x\
3*sin |-|*cos|-|
\2/ \2/
----------------
2
case 5x^2
Introduce la funcion 5x^2
parse error:
syntax error
>>> 5x^2
^
error: called from
symbolic at line 6 column 2

Please specify the error in this octave code

So I am trying to solve this problem from coursera regarding onevsAll classification. It comes under the ml course under Andrew NG. I am not able to find mistake in my code and it keeps showing this error
error: fmincg: operator +: nonconformant arguments (op1 is 401x1, op2 is 4x1)
error: called from
fmincg at line 87 column 5
oneVsAll at line 60 column 13
ex3 at line 77 column 13
I have tried reading the fmincg code but I cannot understand the problem.
function [all_theta] = oneVsAll(X, y, num_labels, lambda)
% Some useful variables
m = size(X, 1);
n = size(X, 2);
% You need to return the following variables correctly
all_theta = zeros(num_labels, n + 1);
% Add ones to the X data matrix
X = [ones(m, 1) X];
for c = 1:num_labels
initial_theta = zeros(n+1,1) ;
options = optimset('GradObj', 'on', 'MaxIter', 50);
[theta] = fmincg (#(t)(lrCostFunction(t, X, (y == c), lambda)),initial_theta, options);
all_theta(c, :) = theta;
end;
Program is showing error mentioned above regarding the fmincg file.

Noncomformant arguments error although using element-wise operations

I am using element-wise operation and am still getting the error nonconformant arguments in Octave. The code has been given below
function g = sigmoid(z)
g = zeros(size(z));
% Instructions: Compute the sigmoid of each value of z (z can be a
% matrix,vector or scalar).
g = 1./(1+exp(-z));
end
The error is
"error: sigmoid: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x4)"
Could someone please help? Thanks

Octave - System of differential equations with lsode

here is my problem. I'm trying to solve a system of two differential equations thanks to the two functions below. The part of the code that give me some trouble is the variable "rho". "rho" is a function which values are given from a file and that I tried to put in the the variable rho.
function [xdot]=f2(x,t)
# Parameters of the equations
t=[1:1:35926];
x = dlmread('data_txt.txt');
rho=x(:,4);
beta = 0.68*10^-2;
g = 1.5;
l = 1.6;
# Definition of the system of 2 ODE's :
xdot(1) = ((rho-beta)/g)*x(1) + l*x(2);
xdot(2) = (beta/g)*x(1)-l*x(2);
endfunction
.
# Initial conditions for the two variables :
x0 = [0;1];
# Definition of the time-vector -> (initial time,temporal mesh,final time) :
t = linspace (1, 10, 10000);
# Resolution with the lsode routine :
x = lsode ("f2", x0, t);
# Plot of the two curves :
plot (t,x);
When I run my code, I get the following error:
>> resolution_effective2
error: f2: A(I) = X: X must have the same size as I
error: called from
f2 at line 34 column 9
resolution_effective2 at line 8 column 3
error: lsode: evaluation of user-supplied function failed
error: called from
resolution_effective2 at line 8 column 3
error: lsode: inconsistent sizes for state and derivative vectors
error: called from
resolution_effective2 at line 8 column 3
I know that my error comes from a mismatch of size between some variable but I have been looking for the error for days now and I don't see. Could someone try to give and explain me an effective correction ?
Thank you
The error might come from your function f2. Its first argument x should have the same dimension as x0 since x0 is the initial condition of x.
In your case, whatever you intent to be the first argument of f2 is ignored since in your function you do x = dlmread('data_txt.txt'); this seems to be a mistake.
Then, xdot(1) = ((rho-beta)/g)*x(1) + l*x(2); will be a problem since rho is a vector.
You need to check the dimensions of x and rho.

How to make multiplication in octave?

I need to multiply some values bys using this line of code:
% Apply hypothetical keys
tmp = bitxor( Y_i*ones(1,length(K)) , ones(length(Y_i),1)*K );
The error that I found is:
error: binary operator `*' not implemented for `int32 matrix' by `matrix' operations
error: evaluating binary operator `*' near line 49, column 17
error: evaluating argument list element number 1
error: evaluating assignment expression near line 49, column 7