## Struggling with equation and FOR loops

### Serena Solanki (view profile)

on 8 Nov 2017
Latest activity Commented on by Guillaume

### Guillaume (view profile)

on 8 Nov 2017
Hi I am trying to code this equation into MATLAB, I have tried using for loops but have had no success
The code is as follows:
r=[1 2 3 4 5]
Ai=0.6895
%Ai+r=N
N=[0.3256 0.2254 0.1300 0.07684]
%delta =(1/r)*log(Ai/N)]
I want to solve the equation delta and find delta values for each of the Ai/N values. So I would like to achieve 1/1*log(Ai/0.3256), 1/2*log(Ai/0.2254) etc
Hope you can help

### Torsten (view profile)

on 8 Nov 2017
Edited by Torsten

### Torsten (view profile)

on 8 Nov 2017

Ai=0.6895;
r=[1 2 3 4 5];
N=[0.3256 0.2254 0.1300 0.07684];
for i=1:numel(r)
for j = 1:numel(N)
delta(i,j)=1/r(i)*log(Ai/N(j));
end
end
Best wishes
Torsten.

Serena Solanki

### Serena Solanki (view profile)

on 8 Nov 2017
Hi Torsten
Thank you very much for this- it has worked perfectly :)
Guillaume

### Guillaume (view profile)

on 8 Nov 2017
Well, if that's the desired result, and if using matlab R2016b or later, simply:
delta = 1./r'.*log(Ai./N);
And if using matlab < R2016b:
delta = bsxfun(@times, 1./r', log(Ai./N));
No need for loops in any case.