필터 지우기
필터 지우기

Loss is still larger than 30?

조회 수: 3 (최근 30일)
arian hoseini
arian hoseini 2024년 5월 24일
댓글: Steven Lord 2024년 5월 24일
Loss is still larger than 30?
i need these columns a(:,2:2:24) to be close to these ones a(:,1:2:24) and a(:,2:2:24) should be smaller than a(:,1:2:24)
Loss = zeros(27, 12); % Adjust the size according to the number of pairs
for ii = 1:27
colIndex = 1; % Initialize column index for Loss matrix
for i = 1:2:24
% Calculate initial loss
Loss(ii, colIndex) = (a(ii, i) - a(ii, i+1)) * 100 / a(ii, i);
% Check condition and adjust if necessary
if Loss(ii, colIndex) < 0 && a(ii, i) < a(ii, i+1)
a(ii, i) = a(ii, i+1) + 0.00004;
elseif Loss(ii, colIndex) > 30
a(ii, i+1) = a(ii, i) - 0.00004;
end
% Recalculate loss after adjustment
Loss(ii, colIndex) = (a(ii, i) - a(ii, i+1)) * 100 / a(ii, i);
colIndex = colIndex + 1; % Increment column index for Loss matrix
end
end
% Display the updated matrix 'a'
disp(a);
% Display the Loss matrix
disp(Loss);
  댓글 수: 2
John D'Errico
John D'Errico 2024년 5월 24일
편집: John D'Errico 2024년 5월 24일
How can we possibly help you, if you do not supply the matrix a? Even then, if we are given no clue what this code is supposed to do, it is just random code. Since it does not do what you seem to expect it to do, then it might not even be correct code.
I've tried the tea reading toolbox, to see if it would tell me what a is, but it was of no value. Admittedly, I may have used the wrong kind of tea. And since I dropped my crystal ball, it now has a large crack in it. The new one is on order, but you know how mail order works these days.
arian hoseini
arian hoseini 2024년 5월 24일
sorry i forgot to add my data

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

답변 (1개)

Steven Lord
Steven Lord 2024년 5월 24일
Let's take a look at a few lines of your code. I've commented them out since I want to also run some code and these code snippets would not execute.
%{
elseif Loss(ii, colIndex) > 30
a(ii, i+1) = a(ii, i) - 0.00004;
end
%}
So if this else block executes we know that a(ii, i+1) - a(ii, i) is effectively -0.00004. So what does that mean for your recalculation?
%{
% Recalculate loss after adjustment
Loss(ii, colIndex) = (a(ii, i) - a(ii, i+1)) * 100 / a(ii, i);
%}
a(ii, i) - a(ii, i+1) is effectively 0.00004 (from above, multiplying both sides of "a(ii, i+1) - a(ii, i) = -0.00004" by -1.) That times 100 is 0.004. Can 0.004/a(ii, i) be greater than 30? Let's take one value greater than 30 and see if we can find a value for the value that makes 0.004/x equal to it.
syms x
digits(5)
vpasolve(0.004/x == 31)
ans = 
0.00012903
Is there something about your code that rules out a(ii, i) being equal to 0.0012903? [Of course, a simpler way to compute that would be]
0.004/31
ans = 1.2903e-04
Can other values of x satisfy 0.004/x > 30?
fplot(@(x) 0.004./x, [1e-5 1e-3])
yline(30, ':')
Any x where the solid line is above the dotted line would make that correction greater than 30.
x = 0.004/100 % makes the correction 100
x = 4.0000e-05
figure
fplot(@(x) 0.004./x, [1e-5 1e-3])
yline(30, ':')
line(x, 100, Marker='o')
That marker looks pretty squarely on the blue curve to my eye.
Depending on what you're trying to do you should consider using a while statement (to keep adjusting the elements of the a vector while the condition is not satisfied instead of if the condition is not satisfied.)
  댓글 수: 4
arian hoseini
arian hoseini 2024년 5월 24일
I want to set loss to under 30 and after that i need to change those that has upper 30 loss and i need these columns a(:,2:2:24) to be close to these ones a(:,1:2:24) and a(:,2:2:24) should be smaller than a(:,1:2:24) cause a(:,1:2:24) are the real parameters
Steven Lord
Steven Lord 2024년 5월 24일
Setting the corresponding elements of a to be 1 and 1+eps would satisfy the requirements you stated in your comments. But I'm guessing that isn't going to satisfy the requirements you haven't stated. What are those unstated requirements?
a1 = 1+eps;
a2 = 1;
Loss = (a2-a1)*100/a2
Loss = -2.2204e-14
a1 is close to a2. a2 is smaller than a1.
isSmaller = a2 < a1
isSmaller = logical
1
The corresponding Loss value is less than 30 (both in value and in absolute value.)
isLessThan30 = (Loss < 30) & (abs(Loss) < 30)
isLessThan30 = logical
1
Are they an acceptable solution to your problem? Why or why not?

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by