1

I would love to know why this code is not working. if anyone has any information on what is causing matlab to find so many errors, it would be greatly appreciated.

m = 1;
c = 1.5;
fun =@(x, epsilon) 1 .* (1 - (1 - cos(x))/(2.*epsilon)).^c .* cos(m.*x);
a = @(ep) acos(1-(2*ep));

lm =@(e) 1/(2.*pi) .* integral(@(x)fun(x, e), -1.*a(e), a(e));
fprintf('ball bearing at 0.6 is %4.4f', lm(0.6));

the function that I am trying to replicate is 𝐼𝑚(𝜀) =1/2𝜋∫[1 − (1 − cos(𝑥))/2𝜀]^𝑐 cos(𝑚𝑥)dx

There should be no need for the dot modifier on the multiplication to my knowledge, however Matlab was complaining that this required element-wise operations even though there are no matrices involved.

2
  • 1
    This ran for me as is using 2017b, giving the output ball bearing at 0.6 is 0.2416. Commented Nov 23, 2018 at 0:44
  • “So many errors”. Please copy-paste the errors so we can see them too. It helps in finding out what the problem could be. Commented Nov 23, 2018 at 2:05

1 Answer 1

1

According to the documentation of integral the function to be integrated must be vectorized:

For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y. This generally means that fun must use array operators instead of matrix operators. For example, use .* (times) rather than * (mtimes).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.