How to plot solution data with respect to another variable ?
Mostrar comentarios más antiguos
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
Abhivandan Pandey
el 12 de Jun. de 2020
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
Cheol Hwan Park
el 12 de Jun. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
