MATLAB: How to plot solution data with respect to another variable

symbolic toolbox

Hi
I got the solution of nonlinear equation as followed;
>> syms f y_A0 y_B0 y_C0 P T
for y_A0 = 0.5:0.1:0.9;
y_B0 = 1-y_A0;
y_C0 = 0;
P = 2;
T = 423;
equation1 = (y_C0+f*y_A0)*(1-2*f*y_A0)^2/(y_A0-f*y_A0)/(y_B0-2*f*y_A0)^2/P^2 - exp(11454/T-28.36);
equation2 = y_A0-f*y_A0 > 0 ;
equation3 = y_B0-2*f*y_A0 > 0 ;
equ = [equation1 equation2 equation3 ];
solution = solve(equ,f);
double(solution)
end
ans =
0.1558
ans =
0.1007
ans =
0.0588
ans =
0.0283
ans =
0.0082
I want to plot the data of solution with respect to 'y_A0', but only data in last case (y_A0 = 0.9) is saved in the workspace.
I want to gather data in all cases (0.5<= y_A0 <= 0.9) and plot (solution, y_A0) to observe the change of solution with respect to y_A0
How can solve this problem?
I attached the mat. file

Best Answer

syms f y_A0 y_B0 y_C0 P T
y_A0_vals = 0.5:0.1:0.9;
num_y_A0 = length(y_A0_vals);
solutions = zeros(1, num_y_A0);
for y_A0_idx = 1 : num_y_A0
y_A0 = y_A0_vals(y_A0_idx);
y_B0 = 1-y_A0;
y_C0 = 0;
P = 2;
T = 423;
equation1 = (y_C0+f*y_A0)*(1-2*f*y_A0)^2/(y_A0-f*y_A0)/(y_B0-2*f*y_A0)^2/P^2 - exp(11454/T-28.36);
equation2 = y_A0-f*y_A0 > 0 ;
equation3 = y_B0-2*f*y_A0 > 0 ;
equ = [equation1 equation2 equation3 ];
solution = solve(equ,f);
solutions(y_A0_idx) = double(solution);
end
plot(y_A0_vals, solutions)