how do i find the interception of these two fuctions i1 and i2
1 view (last 30 days)
Show older comments
Alexander Singh
on 10 Oct 2021
Commented: Star Strider
on 12 Oct 2021
% hemuppgift 3
a = 0.5;
ih = 10.^-7;
iz = 10.^-5;
F = 96485;
R = 8.134;
T = 298.15;
h= 0.0001;
x = -1:h:1;
z1 = -1.87:h:0.13;
z2 = -2.32:h:-0.32;
%
% E1 = @(z) (x - 0.87);
% E2 = @(z) (x - 1.37);
i1 = @(x) (ih*(exp((a*F*x)/(R*T)) - exp((-a*F*x)/(R*T))));
i2 = @(x) (iz*(exp((a*F*x)/(R*T)) - exp((-a*F*x)/(R*T))));
logh = log10(i1(x));
logz =log10(i2(x));
plot(logh,z1, 'b')
hold on
plot(logz,z2, 'r')
0 Comments
Accepted Answer
Star Strider
on 10 Oct 2021
This was a challenge!
I tried this a couple times before I had an appropriate insight to calculating the intersection. (I made a few minor changes in the code, specifically changing ‘logh’ and ‘logz’ to anonymous functions for clarity, however other than my additions to it that are required in order to calculate the intersection, and that are all commente-documented, it is otherwise unchanged.)
There is only one real intersection, that being (-4.06,-1.21).
% hemuppgift 3
a = 0.5;
ih = 10.^-7;
iz = 10.^-5;
F = 96485;
R = 8.134;
T = 298.15;
h= 0.0001;
x = -1:h:1;
z1 = -1.87:h:0.13;
z2 = -2.32:h:-0.32;
%
% E1 = @(z) (x - 0.87);
% E2 = @(z) (x - 1.37);
i1 = @(x) (ih*(exp((a*F*x)/(R*T)) - exp((-a*F*x)/(R*T))));
i2 = @(x) (iz*(exp((a*F*x)/(R*T)) - exp((-a*F*x)/(R*T))));
logh = @(x)log10(i1(x));
logz = @(x)log10(i2(x));
common_z = linspace(min([z1,z2],[],2), max([z1,z2],[],2), 1E+3); % Common 'z' Vector (Created From 'z1' & 'z2')
common_logh = interp1(z1, real(logh(x)), common_z); % 'logh' Interpolated To 'common_z'
common_logz = interp1(z2, real(logz(x)), common_z); % 'logz' Interpolated To 'common_z'
common_dif = common_logh - common_logz; % Difference
Lidx = ~isnan(common_dif); % Remove 'NaN' Values
z_intx = interp1(common_dif(Lidx), common_z(Lidx), 0) % Calculate 'z' Intersection
logh_intx = interp1(z1, logh(x), z_intx) % Calculate 'logh' Intersection (Can Also Use 'logz')
figure
plot(real(logh(x)),z1, 'b')
hold on
plot(real(logz(x)),z2, 'r')
yline(z_intx, '-g')
xline(real(logh_intx), '-g')
legend('logh', 'logz', 'Intersection Lines', 'Location','best')
figure
plot(x, real(logh(x)), 'b')
hold on
plot(x, imag(logh(x)), ':b')
plot(x, real(logz(x)), 'r')
plot(x, imag(logz(x)), '--r')
grid
title('Plotted As Funcitons Of ‘x’')
Experiment to get different results.
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!