Small matlab code not working. Why ?

Click For Summary

Discussion Overview

The discussion revolves around a MATLAB code that is not functioning as expected, specifically encountering an error related to the variable 'mubeton'. Participants explore potential reasons for the error and suggest debugging strategies.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant points out that the error may be due to the use of "mubeton(1)" in the code, suggesting that MATLAB might misinterpret it.
  • Another participant expresses confusion, affirming that using "mubeton(1)" is intended to access the first value of the vector.
  • A later reply acknowledges a rushed suggestion and advises disregarding it, indicating a lack of thorough review.
  • Suggestions are made to break down the long line of code where 'mubeton(1)' is used into smaller parts to improve clarity and potentially resolve the error.
  • One participant recommends setting a temporary variable to 'mubeton(1)' to check if it is accepted, indicating a method to troubleshoot the issue.
  • A participant reports success after rewriting the code with more intermediate calculations, suggesting that the problem was resolved through this approach.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the exact cause of the error, but there is agreement on the strategy of breaking down complex lines of code for better debugging.

Contextual Notes

The discussion does not include the complete code, which may limit the ability to reproduce the error and fully understand the context of the problem.

imsolost
Messages
18
Reaction score
1
Code is the following :
Matlab:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xiter=[0.7 20 10];
mubeton=[0.100 0.80 0.70 0.60 0.50 0.25];
muair=[0.05 0.042 0.04 0.032 0.021 0.011];
zl=[5 30 70 100];

fnorm1 = @(d,a0,dmax) (a0*(1-exp(-(0.5*log(d./dmax)).^2))+exp(-(0.5*log(d./dmax)).^2));
fnorm2 = @(d,dmax,DRL) exp(-(d-dmax)./DRL);
integ=integral(@(r)((r<xiter(2)).*fnorm1(r,xiter(1),xiter(2))+(r>=xiter(2)).*fnorm2(r,xiter(2),xiter(3))),0,inf); %xiter manquant en input
funny=@(r,xiter)((r<xiter(2)).*fnorm1(r,xiter(1),xiter(2))+(r>=xiter(2)).*fnorm2(r,xiter(2),xiter(3)))./integ;

eps=@(r)(integral2(@(R,phi)(exp(-mubeton(1).*(sqrt((zl(1)+r).*(zl(1)+r) + R.*R) - zl(1).*sqrt((zl(1)+r).*(zl(1)+r) + R.*R)./(zl(1)+r))-muair(1).*(zl(1).*sqrt((zl(1)+r).*(zl(1)+r) + R.*R)./(zl(1)+r))).*R./(2.*sqrt(R.*R+(zl(1)+r).*(zl(z1)+r)))),0,inf,0,2*pi));
%produit=@(y)((eps(y)).*((funny(y,[0.7 20 10]))));
integral(@(y)((eps(y)).*((funny(y,[0.7 20 10])))),0,inf,'ArrayValued',true)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error is the following :

"Undefined function 'mubeton' for input arguments of type 'double'."

Why the hell MATLAB thinks this is a function wile its clearly expressed as a vector ?

Thx for any help guys :)
 
Last edited by a moderator:
Physics news on Phys.org
Perhaps because you have "mubeton(1)"?
 
Thank you for your answer but i don't get what you mean. I want indeed to use the first value stored in the vector mubeton. So mubeton(1) seems right to me.
 
Sorry, I made a rushed suggestion on my way out the door without looking at your code properly so please disregard my answer.
 
The line where mubeton(1) is used is awfully long. Have you tried to break that up into multiple lines of smaller intermediate results? Thinking an interpreter weirdness. [EDIT: not likely. Have you tried a clear all?] Also this is not the whole code, so I can't reproduce your error message.
 
Last edited:
  • Like
Likes   Reactions: FactChecker
I suggest breaking that huge line defining eps into several "baby-step" intermediate calculations on separate lines. Error messages are no always exact about the error location.
Before that bunch of smaller lines, set temp1 = mubeton(1) and see if it accepts it.

PS. I don't have MATLAB so I can't give specific help.
 
lewando said:
The line where mubeton(1) is used is awfully long. Have you tried to break that up into multiple lines of smaller intermediate results? Thinking an interpreter weirdness. [EDIT: not likely. Have you tried a clear all?] Also this is not the whole code, so I can't reproduce your error message.

I followed your suggestion and rewrote the code with more intermediate calculation subfunctions. It worked since problem seems to be gone.

Thank you all guys for this help.
 
  • Like
Likes   Reactions: FactChecker

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K