how can I call a function which get the answers numberically

2 次查看(过去 30 天)
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:)

采纳的回答

John Petersen
John Petersen 2012-7-10
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 个评论
Image Analyst
Image Analyst 2012-7-11
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by