# Storing values from a loop when both sym and solve is involved?

1 view (last 30 days)
gabriel rios on 20 Nov 2019
Answered: Kavya Vuriti on 14 Jan 2020
for V = [20:1:40]
syms ho L
Redo = V * d1 / vo; %IGNORE FOR THIS QUESTION
Nudo = 0.3 + [0.62.*Redo.^(1/2).*Pri.^(1/3).*[1+(0.4./Pro).^(2/3)].^(-1/4)].*[1+(Redo./282000).^(5/8)].^(4/5); %IGNORE FOR THIS QUESTION
eq2 = ho * d1 / ko == Nudo; %IGNORE FOR THIS QUESTION
ho = solve(eq2,ho); %IGNORE FOR THIS QUESTION
ho = round(double(ho),3); %IGNORE FOR THIS QUESTION
U = (1/ho + 1/hi).^-1; %INGNORE FOR THIS QUESTION
eq3 = (tg1 - tw2) / (tg1 - tw1) == exp((-pi*d1*L*U)/(mf*cpi)); %solving for L from this eq.
L = solve(eq3,L); %solving for L
L = round(double(L),3) %simplify L with few decimal places
end
I am looking for various values of L when V is 20-40. RUNNING THE CODE AS IT IS SHOWN, I get individual L values that over ride themselves up until when V = 40.
I want to store ALL the values of L that the code is spitting into a matrix for plotting.
After research, I tried trading the last 2 L with
L(V)
But that gave me a matrix with 1 value, and the rest = 0. Changing all L to L(V) gives me an error with my other syms variable "ho".
What can I do? I am getting the correct values I want with the code above, but I wan't to plot those values, and I can't do it because L keeps getting overwritten.

Kavya Vuriti on 14 Jan 2020
Hi,
Assuming the values of L to be numeric, you could try declaring an empty variable and then append the values obtained, each time the for loop runs to this variable. It could look something like the code below:
sol= [];
for v = 20:40
% remaining lines of code
L = round(double(L),3);
sol = [sol L];
end
% plot the values of L
plot(sol);