Function output is only ans, how do it get output as variable?

조회 수: 5 (최근 30일)
Brian
Brian 2014년 10월 26일
댓글: Jan 2014년 10월 26일
Hi, I know this is probably a simple fix, but i just started using MATLAB, and am having trouble getting my function to output something other than ans. Here is my code, the input that I am using is x=(0:.01:50) and r=.5:
function [y,dy] = func(x,r)
y=((1+r)*exp((x)))./(1+(r*(exp((1+r)*((x))))));
dy= ((1+(r*(exp((1+r)*((x)))))* (diff(((1+r)*exp((x)))))-((1+r)*exp((x)))* diff((1+(r*(exp((1+r)*((x)))))))))/((1+(r*(exp((1+r)*((x))))))^2);
end
since I am defining y and dy, I thought each answer would be in its own matrix.
  댓글 수: 1
Jan
Jan 2014년 10월 26일
Star Stride hit the point: You have to call your function exactly as you assign the values to y and dy in your code and as you use the built-in functions exp, +, *, ./, diff and ^.
Such basic questions are explained exhaustively in teh Getting Started chapters of the documentation. It is recommended to study them carefully.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2014년 10월 26일
The both should appear if you ask them to.
Try this:
x=(0:.01:50);
r=.5;
[y,dy] = func(x,r)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by