Plotting with an injected numerical solution as an argument
Show older comments
I have a numerical solution "a" of an equation which is obtained for a "specific value of T and k". I want to insert this solution inside a function which is then to be plotted.
In the plot function I also have same variables, and plot is for a "range of T values" (on x-axis) and fixed k. Now the numerical solution is only for a fixed T value, so it is not well synchronized with the plot function. Is there a way to tie these two (numerical solution+plot function), so I can define T and other same variables once and for all?
The code for numerical solution is
syms a
v2=-2.375; g=1; b=0.00001; e2=0.5; k=pi/2; T=1.1; w=-2*cos(k);
eqn = sin(3*k+a)/sin(2*k+a)==v2-w+(g.*T.^2)./(1+b.*T.^2)+(e2.*T.^2.*sin(k)^2)./(sin(2*k+a)^2+b*T.^2*sin(k)^2);
sol = solve(eqn,a,[0 pi]);
solutions=vpa(subs(sol),3)
The above numerical solution(s) is to be injected inside the argument of `cosine` function below and then plotted. The code for plotting function is
v0=-2.5; epsilon=0.05; v1 = v0*(1+epsilon); v2 = v0*(1-epsilon); g = 1;
T=[0:0.01:3];
k=pi/2
l=-k
w=-2*cos(k)
w1=-2*cos(l)
nu = @(T) v2-w+g.*T.^2;
delta = @(T) v1-w+g.*T.^2.*(1-2.*nu(T)*cos(k+solutions)+nu(T).^2);
nu1 = @(T) v1-w1+g.*T.^2;
delta1 = @(T) v2-w1+g.*T.^2.*(1-2.*nu(T)*cos(k+solutions)+nu(T).^2);
fplot(@(T) abs((exp(i*k)-exp(-i*k))/(1+(nu(T)-exp(i*k)).*(exp(i*k)-delta(T))))^2,[0,5],'--r')
hold on
fplot(@(T) abs((exp(i*l)-exp(-i*l))/(1+(nu1(T)-exp(i*l)).*(exp(i*l)-delta1(T))))^2,[0,5],'b')
hold off
legend('k=\pi/2','k=-\pi/2')
4 Comments
Jan
on 4 Dec 2018
What does "not well synchronized with the plot function" mean? "can define T and other same variables once and for all" is not clear tome also. What is "injecting"?
Torsten
on 4 Dec 2018
Use T as a second symbolic variable. Then you can substitute T in the solution by the numerical values 0:0.01:3.
AtoZ
on 4 Dec 2018
Answers (0)
Categories
Find more on Mathematics 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!