calculate coefficient C. while loop nested in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hey,
I'm trying to create a program which follows the formula ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/786308/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/786308/image.jpeg)
the vector must have at least two elements. Here is my code so far which I belive has the wrong nested while loop so the program never ends.
clc
clear
v=[0 4 2 6];
c=0;
deltaL=.5;
for i=1:length(v)
while v(i+1)<= length(v)
c=c+((v(i+1)-v(i))/deltaL);
end
end
c
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 11 月 1 日
v = [0 4 2 6];
deltaL = .5;
c = sum(diff(v) ./ deltaL)
c_shortcut = (v(end) - v(1)) ./ deltaL
You should recheck your formula: unless deltaL can change for each item, then mathematically your c has to equal what I calculate in c_shortcut
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!