How do I set some variables of a function to a constant and plot the others?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zachary
am 25 Okt. 2022
Kommentiert: Davide Masiello
am 25 Okt. 2022
I defined a function Theta of two variables. What is the simplest way to set one variable to a constant and make a 2D plot using the other variable? For instance, I would like to set Delta = 1 and plot Theta(E,1) over E -3:.001:3?
function Theta = Theta(E,Delta)
if abs(E)<Delta
Theta = pi/2 + 1i*atanh(E/Delta);
elseif abs(E)>Delta
Theta = 1i*atanh(E/Delta);
end
end
0 Kommentare
Akzeptierte Antwort
Davide Masiello
am 25 Okt. 2022
Bearbeitet: Davide Masiello
am 25 Okt. 2022
This is a possibility
E = -3:.001:3;
plot(E,Theta(E,1))
function out = Theta(E,Delta)
out = zeros(size(E));
out(abs(E)<=Delta) = pi/2+1i*atanh(E(abs(E)<=Delta)/Delta);
out(abs(E)>Delta) = 1i*atanh(E(abs(E)>Delta)/Delta);
end
4 Kommentare
Davide Masiello
am 25 Okt. 2022
Sorry for the slow response, I don't have anything to add to John's extensive explanation.
Just mind that the function as it is now works only in case you want to keep delta constant and plot theta vs E.
More robust codes can be implemented depending on your needs.
Lastly, if you think the answer is comprehensive enough and helped, please consider accepting it.
Cheers
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!