# lsqnonlin with vector input and multiple equations.

4 visualizaciones (últimos 30 días)
Emma Van Puyenbroeck el 21 de Feb. de 2020
Respondida: Pravin Jagtap el 24 de Feb. de 2020
when I try to run my model I always receive the error 'Undefined function or variable 'x'.'
How should I specify my variable x?
function y=testst(T_1,T_2,P_c,Q_gen)
x_1=0.35
x_2=0.21
y_3=0.85
h_1=1500
h_2=500
h_3=230
f(1)=x(1)-x(2)-x(3);
f(2)=x_1*x(1)-x_2*x(2)-y_3*x(3);
f(3)=Q_gen+x(1)*h_1-x(2)*h_2-x(3)*h_3;
st=[0.005 ;0.005; 0.005]';
lb=[0; 0 ;0];
ub=[1 ;1 ;1];
y=x
end
I also tried this:
st=[0.005 ;0.005;0.005];
lb=[0; 0 ;0];
ub=[1 ;1;1];
f(1)=x(1)-x(2)-x(3);
f(2)=x_1*x(1)-x_2*x(2)-y_3*x(3);
f(3)=Q_gen+x(1)*h_1-x(2)*h_2-x(3)*h_3;
end
but than I had 'not enough input arguments'
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Pravin Jagtap el 24 de Feb. de 2020
Hello Emma,
The error mentioned is caused because of the way 'function handle' is used (steadystate=@(x) f(x);). In your case, it is better to write the separate function which returns 'f(1)', 'f(2)' and f(3) values. Please refer to the following example for creating the function handle:
function f = get_f(x)
f(1) = x(1);
f(2) = x(2);
f(3) = x(3);
end
Then, run the following script to see how to create the function handle:
f = @get_f;
x = [1 2 3];
Here, ‘steadystate’ will be 1x3 vector. Modify your code using above reference and for more details on how to use function handles use the following documentation link:
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Box Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by