why cant multiply an anonymous function with a changing variable?

clc
clear
f=10000;
w=2*pi*f;
mr=linspace(1,10,5);
m0=pi*4e-7;
m=mr.*m0; %magnetic permability
s1=10*1e6;
a1=@(a) sqrt(a.^2+1j.*w.*m.*s1);
x=integral(a1,1,3000)
%%%% the result at matlab is:
Error using +
Matrix dimensions must agree.

댓글 수: 1

Why did you flag your question as unclear? Apart from not using correct formating for your code I don't see how your question is unclear. I will remove the flag. If you think this question needs a flag after reading this thread feel free to flag your question again, adding an explanation.

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

 채택된 답변

Steven Lord
Steven Lord 2020년 4월 3일

1 개 추천

integral will call your function with a vector of values and expects your function to return a vector of the same size. w and s1 are scalars but m is a vector. There's no guarantee that m and a will be vectors of the same size, and even if they were I'm not certain that would do what you want.
If the function you're trying to integrate is an array-valued function, specify the 'ArrayValued' option with value true in your integral call. This will cause integral to call your function with a scalar instead.

댓글 수: 1

Okay i changed it.
It worked and the result that i get its the right one.
Thanks a lot!
Best wishes!

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

추가 답변 (0개)

카테고리

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

태그

질문:

2020년 4월 3일

댓글:

Rik
2020년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by