How to solve a single nonlinear equation with parameter variations?
Mostrar comentarios más antiguos
#Function file
function f=reso(A,w)
global taue k gamma hac;
f=(((taue+k.^2)-w.^2)*A+(9/2)*A.^3-(75/64)*A.^5).^2+(gamma*k*w*A).^2-hac.^2;
end
Script file
global taue k gamma hac;
taue=0.95;
L=5;
k=pi/(2*L);
hac=1.46;
gamma=0.95;
A0=0.001; %Initial guess
w=0:0.1:5;
for k= 1:length(w)
sol = fzero(@(A) reso(A,w(k)),A0);
plot(w,sol);
end
Here the for loop is not working. Could anybody please point out the problem. Thanks in advance
Respuesta aceptada
Más respuestas (1)
KSSV
el 30 de En. de 2021
It is suggested not to use global.
Replace these lines:
w=0:0.1:5;
for k= 1:length(w)
sol = fzero(@(A) reso(A,w(k)),A0);
plot(w,sol);
end
with
w=0:0.1:5;
sol = zeros(size(w)) ;
for k= 1:length(w)
sol(k) = fzero(@(A) reso(A,w(k)),A0);
end
plot(w,sol)
Categorías
Más información sobre Systems of Nonlinear Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
