Subscript indices must either be real positive integers or logicals. why does this come up?

12 次查看(过去 30 天)
Trial>> AusProfInt(2, 1, 1.5, 3, 100, 0.7)
Subscript indices must either be real positive integers or logicals.
Error in AusProfInt (line 8)
Ausdemand1= -(A*2^2)/2 + (A*((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*(1 +
((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*pa*(-1 + sigma))*2^3)/ (pa*(-3 + sigma)*(2 -
3*sigma + sigma^2)* (((1 + ((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*pa)*sigma*2)/(-1 +
sigma))^sigma) + (A*(pa + 2)^2*(pa*(-2 + sigma) + 2))/ (pa^2*(-3 + sigma)*(2 - 3*sigma
+ sigma^2)* ((sigma*(pa + 2))/(-1 + sigma))^sigma)+ (A*1^2)/2 +
(A*((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*(1 +
((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*pa*(-1 + sigma))*1^3)/ (pa*(-3 + sigma)*(2 -
3*sigma + sigma^2)* (((1 + ((x^1/1-sigma)-1/pa-pc(x)^1/1-sigma)*pa)*sigma*1)/(-1 +
sigma))^sigma)+(A*(pa + 1)^2*(pa*(-2 + sigma) + 1))/ (pa^2*(-3 + sigma)*(2 - 3*sigma +
sigma^2)* ((sigma*(pa + 1))/(-1 + sigma))^sigma);

回答(2 个)

Walter Roberson
Walter Roberson 2016-6-29
In that code, you could get that error if pc is a variable instead of a function and x is not a positive integer. Did you want pc*x instead of pc(x) ?
I note in your code that in several places you have
x^1/1-sigma
or
p(x)^1/1-sigma
I think it is unlikely that you want that code to be like that. x^1 is the same as x, and dividing by 1 would give you the same value you had, so x^1/1-sigma would be the same as x - sigma but I suspect you want x^(1/(1-sigma)) . I recommend, by the way, that you store that (1/(1-sigma)) into a variable in an earlier line and use the variable name instead of repeating the expression.
  5 个评论
Darcy Love
Darcy Love 2016-6-29
编辑:Walter Roberson 2016-6-29
function [AusProfInt]= AusProfInt (pa,AUeX,pc,sigma,A,x)
%sigma= 3;
%A= 100;
w= x^(1/1-sigma);
k= (w)-1/pa-pc*(w);
%x= 0.7;
Ausdemand1= -(A*2^2)/2 + (A*k*(1 + k*pa*(-1 + sigma))*2^3)/ (pa*(-3 + sigma)*(2 - 3*sigma + sigma^2)* (((1 + k*pa)*sigma*2)/(-1 + sigma))^sigma) + (A*(pa + 2)^2*(pa*(-2 + sigma) + 2))/ (pa^2*(-3 + sigma)*(2 - 3*sigma + sigma^2)* ((sigma*(pa + 2))/(-1 + sigma))^sigma)+ (A*1^2)/2 + (A*k*(1 + k*pa*(-1 + sigma))*1^3)/ (pa*(-3 + sigma)*(2 - 3*sigma + sigma^2)* (((1 + k*pa)*sigma*1)/(-1 + sigma))^sigma)+(A*(pa + 1)^2*(pa*(-2 + sigma) + 1))/ (pa^2*(-3 + sigma)*(2 - 3*sigma + sigma^2)* ((sigma*(pa + 1))/(-1 + sigma))^sigma);
Ausdemand2= pa.*Ausdemand1;
sumtotalAus= sum(Ausdemand2);
AusProfInt= pa*sumtotalAus - sum((Ausdemand2*AUeX));
end

请先登录,再进行评论。


Darcy Love
Darcy Love 2016-6-29
is this what you mean? I understand that i need to add brackets in. Even when i add this element in, it still comes out with "NaN"as the answer when i run the function.
Kind regards,

类别

Help CenterFile Exchange 中查找有关 Discontinuities 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by