How to calculate the value of an unknown given three other values?
13 views (last 30 days)
Show older comments
How do I write a function that calculates the exposure settings for a photographer, i.e. of the four values passed to the function (EV, N, t, S), one of the four variables should be zero and this indicates which variable needs to be solved for.
So far this is all I have:
function [EV, N, t, S] = EVfun(EV, N, t, S)
EV_values = linspace(1, 23, 23);
N_values = [25, 50, 100, 200, 400, 800, 1600, 3200];
t_values = [15, 8, 4, 2, 1, 1/2, 1/4, 1/8, 1/15, 1/30, 1/60, 1/125, 1/250, 1/500, 1/1000, 1/2000, 1/4000, 1/8000];
S_values = [1/1, 1/1.4, 1/2, 1/2.8, 1/4, 1/5.6, 1/8, 1/11, 1/16, 1/22, 1/32, 1/45];
for i = numel(EV)
if EV == 0
EV(i) = log2((N(i)^2/t(i))/(S(i/)100))
elseif N == 0
N(i) = sqrt(2^EV(i)*t(i)*(S(i)/100))
elseif t == 0
t(i) = ((N(i)^2)/(2^EV(i))*(S(i)/100))
elseif S == 0
s(i) = (100*(N(i)^2/t(i))/2^EV(i))
end
end
end
Could someone please help me write this function or tell me what to do through pseudocode?
1 Comment
dpb
on 18 May 2014
Edited: dpb
on 18 May 2014
function (EV, N, t, S)
...one of the four variables should be zero and this indicates which variable needs to be solved for.
But the first thing you do is overwrite all the input variables so you've lost the user's input and thereby the flag to test.
Use a different set of variable names internally for the vectors than the dummy argument names.
Then you have to define what it is you're actually looking for -- the loop over EV is for 1:23 elements but none of the other arrays are that long so you will have an indexing issue there.
What do you want the function to actually return, specifically?
Answers (1)
Image Analyst
on 18 May 2014
You have tons and tons of errors in there. I've fixed it some but you still have problems in that your arrays don't have the same length. There is also no log2 function so you'll have to write that.
function test
clc;
EV_values = linspace(1, 23, 23);
N_values = [25, 50, 100, 200, 400, 800, 1600, 3200];
t_values = [15, 8, 4, 2, 1, 1/2, 1/4, 1/8, 1/15, 1/30, 1/60, 1/125, 1/250, 1/500, 1/1000, 1/2000, 1/4000, 1/8000];
S_values = [1/1, 1/1.4, 1/2, 1/2.8, 1/4, 1/5.6, 1/8, 1/11, 1/16, 1/22, 1/32, 1/45];
EV_values = 0;
[EV, N, t, S] = EVfun(EV_values, N_values, t_values, S_values)
function [EV, N, t, S] = EVfun(EV, N, t, S)
if EV == 0
EV = log2((N .^ 2 ./ t) ./ (S/100))
elseif N == 0
N = sqrt((2 .^ EV .* t) .* (S/100))
elseif t == 0
t = ((N .^ 2) ./ (2.^EV) .*(S/100))
elseif S == 0
s = 100*(N .^ 2 ./ t) ./ 2 .^ EV
end
I'm also not sure if I fixed your parentheses (which were messed us) the right way when I vectorized your equations so check over that to make sure the equations do what you want.
0 Comments
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!