Help!!! Mysterious FSOLVE InputOutputModel/vertcat Error!

2 Ansichten (letzte 30 Tage)
Tristan
Tristan am 31 Mai 2013
I'm new to MATLAB and I keep getting this error when I try to solve a system of 10 equations in 10 unknowns:
Error using InputOutputModel/vertcat (line 48)
In "[M1;M2]", M1 and M2 must have the same number of
inputs/columns.
Error in fpiss_fun (line 25)
f = [
Error in @(x)fpiss_fun(x,param)
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Error in Sample (line 14)
x=fsolve(f,x0)
Caused by:
Failure in initial user-supplied objective function
evaluation. FSOLVE cannot continue.
Relevant code:
clear all;
clc;
param = fpi_parameters;
options = optimoptions('fsolve','Display','iter');
x0 = [2.1;1.8;.95;12;9;10;.01;.16;.001;3];
f=@(x)fpiss_fun(x,param);
x=fsolve(f,x0)
___________
function param = fpi_parameters()
param.bet = .99;
param.ak = .005;
param.an = .05;
param.lamk = .01;
param.lamn = .1;
param.epk = .5;
param.epn = .6;
param.dele = .02;
param.delu = .01;
param.chik = 1;
param.chin = 1;
param.alph = .3;
param.zss =1;
param.wss =1.45;
param.rss =0.04;
______________
function f = fpiss_fun(x,param)
%Allows referencing parameters by fieldnames instead of param.fieldname
nms = fieldnames(param);
for j = 1:length(nms)
eval([nms{j} '=' 'param.' nms{j} ';'])
end
%Renaming endogenous variables
y=x(1);
c=x(2);
l=x(3);
n=x(4);
ke=x(5);
ku=x(6);
vk=x(7);
vn=x(8);
thetk=x(9);
thetn=x(10);
%Declaring the system to be solved for (y c l n ke ku vk vn thetk thetn)
f = [
wss*n+rss*ke+lamk*(1-dele)*ke+ku-c-l;
y-zss*n^(alph)*ke^(1-alph);
ke-(1-dele)*(1-lamk)*ke-chik*thetk^(epk)*l;
ku-(1-chik*thetk^(epk))*(1-delu)*l;
n-(1-lamn)*n-chin*thetn^(epn)*(1-n);
ak/(chik*thetk^(epk-1))-bet*(zss*(1-alph)*n^alph*ke^(-alph)-rss+(1-lamk)*(1-dele)*ak/(chik*thetk^(epk-1)));
an/(chin*thetn^(epn-1))-bet*(zss*alph*n^(alph-1)*ke^(1-alph)-wss+(1-lamn)*an/(chin*thetn^(epn-1)));
thetn-vn/(1-n);
thetk-vk/l;
(1-(1-chik*thetk^(epk))*(1-delu)*bet)/(chik*thetk^(epk))*(1-bet*(1-dele)*(1-lamk))-bet*(rss+lamk*(1-dele))
];
Any ideas why this isn't working? Thanks!!!
  1 Kommentar
Alan Weiss
Alan Weiss am 31 Mai 2013
Please edit your post using the {}Code tool as appropriate so we can read it.
Alan Weiss
MATLAB mathematical toolbox documentation

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Mai 2013
Notice that the error is said to occur at InputOutputModel/vertcat instead of at vertcat . If you were using the normal vertcat, the message would say
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
This suggests that in a directory named InputOutputModel that is on your MATLAB path, there is a vertcat.m routine that is being called instead of the built-in vertcat routine. You will need to remove the directory InputOutputModel from your MATLAB path, or else you will need to recode the vertcat there to be type-specific so that it is not found while matlab is searching for its vertcat routine. "vertcat" is the 'real' name of the operation carried out when you use a semi-colon inside []
[a b;c d]
is turned into calls to
vertcat( horzcat(a,b), horzcat(c, d) );
Is it possible you are running this code within Simulink ?
  2 Kommentare
Walter Roberson
Walter Roberson am 23 Apr. 2021
It turns out that InputOutputModel is used for transfer functions and state-space models.
Biplob Chowdhury
Biplob Chowdhury am 3 Jul. 2023
Hi,
I am in the same problem using MATLAB R2019b while simulating a Wind Turbine model. I need to define a state matrix. The state matrix is like this:
Ar = [Aa+Ba*Kx-Lx*Ca, Bda*Theta_dac+Ba*Kd, Ba*Ki; zeros(nxd,nxa)-Ld*Ca, F_dac, zeros(nxd,ni); 0, 0, 0];
The error message is:
Error using InputOutputModel/vertcat (line 47)
In "[M1;M2]", M1 and M2 must have the same number of inputs/columns.
Error in DAC (line 236)
Ar = [Aa+Ba*Kx-Lx*Ca, Bda*Theta_dac+Ba*Kd, Ba*Ki; zeros(nxd,nxa)-Ld*Ca, F_dac, zeros(nxd,ni); 0, 0,
0];
I have checked all the individual elements, the Ba*Ki” gives a message like this:
ans =
Generalized matrix with 14 rows, 1 columns, and the following blocks:
Ki: Parametric 3x1 matrix, 1 occurrences.
Type "double(ans)" to see the current value, "get(ans)" to see all properties, and "ans.Blocks" to interact with the blocks.
I have already checked, and the ‘InputOutputModel’ is not in the MATLAB path.
I would appreciate any help on this.
Best regards

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Alan Weiss
Alan Weiss am 31 Mai 2013
I am not sure what your code does. Can you please try to execute
testvalue = fpiss_fun(x0,param)
where x0 is your initial point? Do you get a result testvalue?
Alan Weiss
MATLAB mathematical toolbox documentation

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by