Subscript indices must either be real positive integers or logicals.
Show older comments
function T=baryeval2(tau,s,c,belta,x)
u=zeros(size(x))
d=zeros(size(x))
T=zeros(size(x))
for k=1:5
u=u+s(k).*belta(k).*(x-tau(k)).^(-1);
d=d+c(k).*belta(k).*(x-tau(k)).^(-1);
end
T=u./d;
end
1 Comment
Azzi Abdelmalek
on 27 Feb 2016
You can copy and paste your code instead of inserting an image.
Answers (4)
Azzi Abdelmalek
on 27 Feb 2016
Edited: Azzi Abdelmalek
on 27 Feb 2016
0 votes
You cant use an index equal to zero, Matlab allows only positive integer indices, or logical indices
4 Comments
Yintong Zheng
on 27 Feb 2016
Walter Roberson
on 27 Feb 2016
Is it possible that you defined "sin" or "cos" as a variable?
I notice that the error message does not correspond to the code you posted. Please post your current code and corresponding error message.
Yintong Zheng
on 27 Feb 2016
Yintong Zheng
on 27 Feb 2016
the cyclist
on 27 Feb 2016
MATLAB has 1-based indexing. When you enter
tau(k)
for k = 0, there is no such element.
1 Comment
Yintong Zheng
on 27 Feb 2016
Walter Roberson
on 27 Feb 2016
0 votes
You have, in part, (x-tau(k)).^(-1) . If there is any x equal to tau(k) then the subtraction would give 0 and raising that to power -1 would give infinity. Infinity times any non-zero value gives infinity (infinity times 0 gives nan), so you would be adding infinity to the value, resulting in infinity. And then since you are effectively totaling values, you are going to get an infinite result.
2 Comments
Yintong Zheng
on 27 Feb 2016
Walter Roberson
on 27 Feb 2016
If you do have an x equal to some tau, then inf or nan is the correct answer for the formulae you have written. The situation is exactly like asking to total 1/x when x is allowed to be 0.
Image Analyst
on 27 Feb 2016
0 votes
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!