# Finding all possible zeros for a function with 2 independent variables.

20 visualizzazioni (ultimi 30 giorni)
Rina Dirickson il 6 Lug 2022
Commentato: Star Strider il 8 Lug 2022
I have the following function where v & n are the independent variables and the others are constants. am(v) and bm(v) are two other separate functions of v.
function f = F(v,n,i,a,b,vNa,vK,vL)
amv = am(v);
bmv = bm(v);
tmv = 1./(amv + bmv);
f = i - 120.*(amv.*tmv).^3.*(b-a.*n).*(v-vNa) - 36.*(n).^4.*(v-vK)-0.3.*(v-vL);
end
I basically want to find the values of v & n where f = 0. I just don't really know where to start when I have two unknowns. I've tried looking at https://www.mathworks.com/help/optim/ug/fsolve.html but it did not make much sense.
The end goal is to graph the values of v and n on a plot, so having it result in a matrix would be useful. I am not sure if that's possible though. Thank you for any help in advance!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 6 Lug 2022
The contour and fimplicit funcitons are likely best for this.
For contour, create a matrix for ‘v’ and ‘n’ using either ndgrid or meshgrid, then specify [0 0] as the contour to plot:
NM = number_of_elements;
vv = linspace(minvalv, maxvalv, N);
nv = linspace(minvaln, maxvaln, N);
[Vm,Nm] = ndgrid(vv, nv);
Fm = F(vv,nv,,i,a,b,vNa,vK,vL);
figure
C = contour(Vm,Nm,Fm, [0 0])
That will plot them. To retrieve the (x,y) values, use find to determine the locations of ‘C(1,:)’ that equal zero, then ‘C(2,:)’ of those indices are the number of (x,y) pairs in the contour. That will determine how to recover them.
It will likely be easier to plot and recover the data from the fimplicit plot.
.
##### 2 CommentiMostra NessunoNascondi Nessuno
Rina Dirickson il 8 Lug 2022
I replaced ndgrid with meshgrid, and used Vm and Nm for the function call and it worked. Thank you so much!
Star Strider il 8 Lug 2022
As always, my pleasure!

Accedi per commentare.

### Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

R2022a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by