Logarithm Matlab - matlab

I try to use the logarithm function to a specific base in Matlab but I get the error message:
"Error using log
Too many input arguments." which I do not understand because the syntax is very simple.
My code is: log(4,2);
Why do I get this error?

matlab's log function (before R2017a) doesn't have this functionality.
instead, you can do: log(x)/log(n), whereas log_n(x) = log(x)/log(n)

Related

Issues with MATLAB butter

I am using MATLAB R2015 and cannot implement 'butter' without getting an error related to too many output arguments from the polyfit part of the script. I have used the same implementation for years with other versions of MATLAB.
Example:
[b, a] = butter(2,[.15,.3]);
Error using poly
Too many output arguments.
Error in zp2ss (line 127)
den = real(poly(p(i:i+1)));
Error in butter (line 97)
[a,b,c,d] = zp2ss(z,p,k);
I get the same error implementing the examples in the help documentation.
Just a guess but is there any chance you've defined your own poly function? which('poly') should point to some Matlab directory unless you've defined it elsewhere, potentially as a variable?. For me on a newer version that path is something like $MATLAB/toolbox/matlab/polyfun/poly.m You can also edit the poly function edit poly and verify that there is one output argument for the function.
Also, I'd advise against ever writing decimal numbers without a leading zero. It took me way to long to figure out what [.15,.3] was. Instead write [0.15,0.3] or even just [0.15 0.3] Edit: I just realized that is an example in Matlab ... my point stands but the toolbox author should know better ...

Error in Matlab code using rand function

I have been using the following matlab code to generate random numbers,
rand('state',0);
n=100;
m=300;
A=rand(m,n);
b=A*ones(n,1)/2;
c=-rand(n,1);
However, it keeps giving me the message "Error in ESE605_Homework_4 (line 1)
rand('state',0)'"I have tried to evaluate the problem, and it says I should switch to using the "rng" function because newer versions of Matlab discourage use of "rand". However, upon switching to the rng, function I am still having issues. Can anyone offer some help?
From Matlab documnetaion
for 'state' option you should use rng function instead of rand

Matlab table function

I have tried running the example as shown in the documentation of MuPAD table:
T := table(a = 13, c = 47)
Doing so gives me the following error:
Undefined function 'T' for input arguments of type 'char'.
I have no idea what is going on. Does anybody know why it isn't working and how I can create a table using this function?
If you look at the top of the page, you are reading about functions contained in the "Symbolic Math Toolbox." I believe you need to pay for that license to use functions from the toolbox.
From Matlab's help for that error you either:
Made a typographical error ...
Changed directories so that a function is no longer on the search path...
Used the wrong case for a function or variable name ...
Are trying to use a function for which you are not licensed.
I got the same error as you, and I also do not have that Toolbox, so perhaps its the last reason.
Is it time to switch to Python?
This happens when you try to call a muPAD function from the MATLAB command line. Whenever you see :=, that's a clue that you're dealing with muPAD. You cannot use muPAD syntax directly in MATLAB (feval or evalin and symengine can be used in some cases to call muPAD functions and return a symbolic expression).
To use table in muPAD:
Call mupad at the command line to open up a muPAD notebook, then call your sample line. You do not need the latest MATLAB version, although I'm not sure exactly when it was brought in (works fine for me on 2011b with Symbolic toolbox).
To use table in MATLAB:
The muPAD table function should not be confused with the MATLAB table function/datatype, which is relatively new. The equivalent in MATLAB of that muPAD code would be something along the lines of (untested):
T = table([13;47],'RowNames',{'a';'c'});

adftest function error in lagmatrix

Using the adftest function in MATLAB's econometrics toolbox, I'm receiving the following error:
>> [h1,pVal1] = adftest(y1,'model','ARD')
Error using lagmatrix (line 25)
lagmatrix: wrong # of input arguments
Error in adftest>runReg (line 705)
yLags = lagmatrix(y,0:(testLags+1));
Error in adftest (line 417)
testReg = runReg(i,y,testT,testLags,testModel,needRegOut);
y1 is a <41x1> vector of doubles.
Has anyone received this error or have any thoughts on what the issue is? I am using this code right out of the box so I'm not sure what is going on. I'd post to MATLAB's site, but it is down for maintenance.
This is either a bug in Matlab, in which case you should submit it on the Matlab support site. Before you do that, you should check that you don't have a function lagmatrix on your path that shadows the built-in function. Type
which lagmatrix
on the command line. If the path does not point to your Matlab installation, you should move lagmatrix off the Matlab search path.
Also note that y1 should not contain all NaN, or be otherwise degenerate, so you may want to check the function using the sample data as suggested in the help to be sure it's a bug and not just your data.
I had the same problem with this function. In my case, the problem was the function lagmatrix (older version) in my MATLAB path and the adftest function was the newest version. The soluction was delete the older version of lagmatrix.

"Not enough input arguments." when using fsolve with nested functions

I am trying to make my own function in matlab to solve for a system of two nonlinear equations, while using a nested function to share some some parameters, here is a sample code:
function y=solve(a,x0)
a;
y=fsolve(nle,x0); % this is line 3
function f=nle(x)
f(1)=x(1)-a*x(1)^2-x(1)*x(2); % this is line 6
f(2)=2*x(2)-x(2)+3*x(1)*x(2);
end
end
Here a is the parameter I want to pass from command line to the function, and x0 is the start point for the fsolve.
However, when I call the function in malab after specifying a=4 and x0=[1 1]', it gave me the following error:
Error using solve/nle (line 6)
Not enough input arguments.
Error in solve (line 3)
y=fsolve(nle,x0);
I'm quite a newbie for matlab, can anybody tell me where I am doing wrong?
Thanks in advance.
EDIT:
I tried substituting the nle with a function handle #nle, but seems something else went wrong:
Undefined function 'fsolve' for input arguments of type 'function_handle'.
Error in solve (line 3)
y=fsolve(#nle,x0);
Doesn't seem to make sense since I checked the documentation for fsolve, and it says it should indeed use a function handle there...
You miss the '#' in front of nle, i.e.
y = fsolve(#nle,x0);
should work.