Borrar filtros
Borrar filtros

how can I call a function which get the answers numberically

2 visualizaciones (últimos 30 días)
Hi,dear all
I have wrote a code for calculating the optimization problem numerically. Now I need to call it in another problem. How can I do this? Because it is not a simple function but contains a lot of if...for... sentences, I don't know what to do.
The gist of the problem is maximizing the dependent variable y through two independent variables x1,x2 for different parameters. But I can't give explicit expression of the function like y=x^2+x or something, so I use fmincon to do the optimization.And it also involves some if...and for sentences because of requirement of the problem. Now I need to call this problem in a another program just like to call a function like y=x^2+x.
I am pretty new to Matlab so my questions may seem quite stupid. But I would appreciate a lot if you can give me some advice:)

Respuesta aceptada

John Petersen
John Petersen el 10 de Jul. de 2012
You didn't give much info on your problem but I assume you just want the form of a function. Here's a simple example.
function [y1,y2,y3] = yourfunction(x1,x2,x3)
y1 = x1+x2+x3;
y2 = x1-x2;
y3 = x2+x3;
That's all there is too it! Did that answer your question?
  3 comentarios
Image Analyst
Image Analyst el 11 de Jul. de 2012
It doesn't matter. Just take the input arguments, do whatever you want with them to create output arguments, and pass the output arguments back to the main function. So in your main function, you'd have this
[y1 y2 y3] = yourfunction(x1, x2, x3);
xueqi
xueqi el 14 de Jul. de 2012
Yes it works!!Thanks:)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by