How to plot solution data with respect to another variable ?

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

2 comentarios

Hi Cheol,
You can plot the required points in several ways. I have written the code for one method below, wherein at each iteration we use plot method to mark the coordinates (y_A0,double(solution)).
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);
plot(y_A0,double(solution),'*');
hold on
end
hold off
Another method is to save the solutions calculated in each iteration in a vector and then use plot after the for-loop with the y_A0 vector and the solution vector as it's argument.
I hope this helps.
Regards,
Abhivandan
It works! I can get the following figure that I want. THANKS Abhivandan for your help

Iniciar sesión para comentar.

 Respuesta aceptada

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)

1 comentario

It works! I can get the well-organized answer and learn this good and advanced method. THANKS Walter !!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Jun. de 2020

Comentada:

el 12 de Jun. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by