I need to calculate a values c2, c3, c4,..., using the equation:
where alpha and beta are the elements of a given vectors of length k. For each q i need to calculate the result. usually Cq will result zero, so i need to find what value of q will be different to zero. I think to do that thing in matlab is using while, but my problem is combine summatory and while in matlab.
for example
in this case the value of k is 2, aplying the equation above for each c2=c3=c4=0 except in c5 which means q=5, by the way values of q start from 2 and above.
Please help me.

댓글 수: 4

Walter Roberson
Walter Roberson 2020년 12월 9일
When do you stop? What is the upper limit for q? Is it expected that once a particular q generates 0 that all higher ones will too?
When you say 0, is that that the terms are literally identical value, or is that a 0 to within some numeric precision? For large enough q the multiplications by j^q are going to result in loss of precision it appears to me, so numeric 0 rather than algebraic 0 would make more sense to me.
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020년 12월 9일
As you can see q starts from 2. In this equation above I need to break the calculation when cq results different to zero. Which implies a value of q not bigger than 100 or 1000 for example in given exercise with a two vector the value of q is five and cq is not zero.
David Hill
David Hill 2020년 12월 9일
You should be able to easily modify my answer to match your indexing.
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020년 12월 9일
I need to break the calculation when a cq is different to zero. I was thinking to use a while loop, to break the calculation when a cq is different to zero. I can use so sum((1:k) expression) inside the while I don’t know maybe can work. Thanks

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

답변 (1개)

David Hill
David Hill 2020년 12월 9일

0 개 추천

C=@(q)sum((1:k).^q.*alpha)/factorial(q)-sum((1:k).^(q-1).*beta)/factorial(q-1);
q=1:100;
c=arrayfun(@(x)C(x),q);
plot(q,c);

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 12월 9일

댓글:

2020년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by