필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by