Iteratively solving using a for loop
Show older comments
Hi there,
I am trying to find the wind shear using the equation (V/Vo) = (H/Ho)^(W) Where W is wind shear.
As of now, I can do it but the for loop using the solve function runs for about 15 minutes to yield 4462 values. WSA490m and WSA3860m are data values enclosed in a csv file, with wind speeds at 49.0m and 38.60m.
if true
Vratio1 = ones(4462,1);
Vratio2 = ones(4462,1);
Hratio1 = (49.0/38.60);
Hratio2 = (59.40/38.60);
LHR1 = log(Hratio1);
LHR2 = log(Hratio2);
WS1 = ones(4462,1); %Wind Shear exponent with 38.60m as reference and 49.0m as the second point
WS2 = ones(4462,1); %Wind Shear exponent with 38.60m as reference and 59.40m as the second point
if true
for r = (1:4462)
Vratio1(r) = (WSA490m(r)/WSA3860m(r));
end
end
if true
for r = (1:4462)
WS1(r) = solve(x == log(Vratio1(r))/LHR1,x);
end
end
Answers (1)
David Goodmanson
on 7 Mar 2018
Edited: David Goodmanson
on 7 Mar 2018
Hi Rnle,
In Matlab you can divide vectors term-by-term with the ./ command to obtain Vratio1. Then, since
W = solve(x = something,x) is the same as W = something
you can determing WS1 in the following way.
WSA490m = rand(4462,1);
WSA3860m = rand(4462,1);
Hratio1 = (49.0/38.60);
Hratio2 = (59.40/38.60);
LHR1 = log(Hratio1);
LHR2 = log(Hratio2);
Vratio1 = WSA490m./WSA3860m;
WS1 = (log(Vratio1)/LHR1);
The two data vectors should be brought into the workspace as complete 4462x1 vectors. After that is done, the rest of it all happens in a couple of milliseconds.
2 Comments
Rnle
on 8 Mar 2018
Star Strider
on 8 Mar 2018
@Rnle —
Since David Goodmanson’s Answer solved your problem, it is appropriate to Accept it.
Categories
Find more on Programming 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!