Effacer les filtres
Effacer les filtres

how can I call a function which get the answers numberically

2 vues (au cours des 30 derniers jours)
xueqi
xueqi le 10 Juil 2012
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:)

Réponse acceptée

John Petersen
John Petersen le 10 Juil 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 commentaires
Image Analyst
Image Analyst le 11 Juil 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 le 14 Juil 2012
Yes it works!!Thanks:)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by