I can't seem to figure our why Matlab doesn't like my function. It keeps telling me that it is probably called incorrectly but I can't see what I did wrong here.
Ideal Boiler Function
hfg=930
lhv=21500
p_percent=100
p=p_percent/100
MFfr=0.5191
%This function will calculate the steam mass flow rate (SMfr)
%of an actual boiler with 100% efficency (p_percent=100%)
%This funtion has 4 inputs (p,hfg,lhv,and MFfr),
%and 1 output (SMfr).
function SMfr=Ideal_Boiler(p,hfg,lhv,MFfr)
SMfr=(MFfr*p*lhv)/hfg;
output=SMfr;
end
disp('SMfr =');disp(SMfr)

 채택된 답변

bio lim
bio lim 2016년 12월 3일

0 개 추천

I don't see any problems, unless you defined the function inside your main script, and MATLAB doesn't allow that.
hfg=930;
lhv=21500;
p_percent=100;
p=p_percent/100;
MFfr=0.5191;
SMfr=Ideal_Boiler(p,hfg,lhv,MFfr)
disp('SMfr =');disp(SMfr)
SMfr =
12.0007
SMfr =
12.0007

댓글 수: 4

Shelby Russ
Shelby Russ 2016년 12월 3일
Um. So, how do I know if it is defined in the main script? I just opened one and saved my file as the function name and it hates me for it. I'm so confused.
bio lim
bio lim 2016년 12월 3일
You need a two .m files, one for your function and one for your main program.
In one of them, you declare your function as:
function SMfr=Ideal_Boiler(p,hfg,lhv,MFfr)
SMfr=(MFfr*p*lhv)/hfg;
output=SMfr;
end
And in your main program, you actually use the values, and call for your function:
hfg=930
lhv=21500
p_percent=100
p=p_percent/100
MFfr=0.5191
SMfr=Ideal_Boiler(p,hfg,lhv,MFfr) % calling Ideal_Boiler function
And the output is:
SMfr =
12.0007
Shelby Russ
Shelby Russ 2016년 12월 3일
Oh my gosh, thank you so much. I would have never figured that out.
bio lim
bio lim 2016년 12월 3일
My pleasure. One more thing:
In your code, if you end a line with a semi-colom, i.e., ; , MATLAB doesn't print out the results. So in your code:
disp('SMfr =');disp(SMfr)
Is unnecessary, if you just end your function call, i.e., SMfr=Ideal_Boiler(p,hfg,lhv,MFfr) without a semi-colon (Meaning it will print the result out).

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

추가 답변 (2개)

Kevin Agudo
Kevin Agudo 2021년 4월 12일

0 개 추천

syms t
function y = f(t)
t=linspace(0,100);
f(x)=(3*t^2+1)./(t^3+50);
h=.01;
plot(t ,(f(t+h)-f(t))./h,t,(f(t+h)-2*f(t)+f(t-h))/h^2)
end
When I run the function, dont get a graph and it says "function f may not be used"

댓글 수: 1

h=.01;
t=linspace(0,100);
plot(t ,(f(t+h)-f(t))./h,t,(f(t+h)-2*f(t)+f(t-h))/h^2)
function y = f(t)
y=(3*t.^2+1)./(t.^3+50);
end

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

Johanan
Johanan 2025년 2월 28일

0 개 추천

Adapt pend.m to build the double pendulum. A new pair of rod and bob must be defined for the second pendulum. Note that the pivot end of the second rod is equal to the formerly free end of the first rod: The (x, y) position of the free end of the second rod can be calculated by using simple trigonometry.

댓글 수: 1

Walter Roberson
Walter Roberson 2025년 2월 28일
I do not understand how adapting pend.m will solve the problem of "Function might be unused" ???

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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2016년 12월 3일

댓글:

2025년 2월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by