Issues with loop- "Too many input arguments."

조회 수: 2 (최근 30일)
Kevin Zhou
Kevin Zhou 2020년 10월 4일
댓글: Star Strider 2020년 10월 4일
Here is my issue- I am on the cusp of solving my problem by using the quadrature technique. However, I seem to be doing something wrong with my loop. Can someone please take a look at this for me:
function [f]= NC_2(n,a,b,fun) %newton-cotes, a and b are limits of integration
for f=1:n
x1= a; %@(leftmost) endpoint
l= (b - a)/n; %length of the sub_interval
x2= x1+l; %the second subinterval endpoint
%setting it up
fa= fun(a); %y value for lower limit
fb= fun(b); %y value for upper limit
%the actual function
f= (b-a)*(fa+fb)/2;
x1= x2; %old endpoint x2 becomes the new x1
x2= x2+l;
end
end
Here is what I type into the command window:
fun= @(x) normpdf(x)
[f]= NC(4,-3,0,fun)
Why is it not working?? Any help is much appreciated!

채택된 답변

Star Strider
Star Strider 2020년 10월 4일
You are not calling it correctly!
See if:
fun= @(x) normpdf(x)
[f]= NC_2(4,-3,0,fun)
does what you want.
  댓글 수: 2
Kevin Zhou
Kevin Zhou 2020년 10월 4일
My bad. you right
Star Strider
Star Strider 2020년 10월 4일
Not your bad!
It’s likely been a long day for us all!

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

추가 답변 (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