フィルターのクリア

how can I call a function which get the answers numberically

2 ビュー (過去 30 日間)
xueqi
xueqi 2012 年 7 月 10 日
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);
xueqi
xueqi 2012 年 7 月 14 日
Yes it works!!Thanks:)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by