Making y-axis positive in both directions
4 views (last 30 days)
Show older comments
I have two sets that I need to graph in opposite directions but both positively counting. So A increasing 0, 1, 2, ... etc. upwards above the x-axis and B increasing 0, 1, 2,...etc. downwards below the x-axis. Here's the exact code I am using right now but a general answer is appreciated. The third En set would also be graphed above the x-axis.
clc
clear
format long
r = 0:.001:1;
A = -1.436;
B = 7.32e-6;
n = 8;
rn = r.^n;
Ea = -1*(A./r);
Er = B./rn;
En = Ea + Er;
hold on
plot(r, Ea, "-.r", r, Er, "--b", r, En)
legend("Attractive Energy","Repulsive Energy","Net Energy")
set(gca, 'YScale', 'log')
xlabel("interionic distance (nm)")
ylabel("Energy (eV)")
title("Interionic Energy vs. Distance Na^+-Cl^- ion pair")
1 Comment
Dyuman Joshi
on 17 Jan 2024
It's not clear to me what the expected output is.
Could you show an example using the figure obtained in the question description?
Answers (1)
Image Analyst
on 17 Jan 2024
Well I think that would be confusing and deceptive to the reader. But anyway, do you want just the exponent to be positive? You can make up y labels with sprintf() and then use yticklabels to have them be whatever you want.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!