필터 지우기
필터 지우기

Why does my anonymous function have an error?

조회 수: 2 (최근 30일)
Natalia Wong
Natalia Wong 2016년 1월 2일
댓글: Natalia Wong 2016년 1월 3일
I can calculate the integral for I1 but not for I2,I3 and I4. I'm new to matlab. I get the error as shown below. But when I plot the graph it's fine. Thanks
Index exceeds matrix dimensions.
Error in Q1d>@(x)(p2(1)*x((6:22)+1).^4)+(p2(2)*x((6:22)+1).^3)+p2(3)*x((6:22)+1).^2+p2(4)*x((6:22)+1)+p2(5)
Error in CompSimp (line 26)
fx = func(x);
Error in Q1d (line 61)
I2 = CompSimp(k,a,b,17)
  댓글 수: 2
Triveni
Triveni 2016년 1월 2일
why are you using "@(x)" ??
Guillaume
Guillaume 2016년 1월 2일
@Ranjan, Please learn about anonymous functions

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

채택된 답변

Guillaume
Guillaume 2016년 1월 2일
It's difficult to answer in great details with so little information, but either x has less than 23 elements when your program reaches line 26 of CompSlim, or p2 has less than 5 elements when the anonymous function is declared.
  댓글 수: 1
Natalia Wong
Natalia Wong 2016년 1월 3일
thanks for helping Guillaume but I managed to solved it already

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by