Make a loop with a function to vary one value
Afficher commentaires plus anciens
Hi I'm currently attempting to make a loop that will make my function vary the eta value. I want it to plot all 5 variations on a single graph. The code can be found below. Any help would be very appreciated.
clearvars
close all
clc
tspan = [0 100];
y0 = 0;
opt = odeset('RelTol',1e-12,'AbsTol',1e-16,'MaxStep',0.001);
[t,y] = ode45(@myfunction,tspan,y0,opt);
plot(t,y); % trying to plot this for the function running a different value of eta each time
function dxdt = myfunction(tt,xx)
E1 = 1000;
E2 = 200;
eta = 10; %vary by 10, 50, 100, 500, 1000
F0 = 5e-10;
F = F0*sin(tt);
dfdt = F0*cos(tt);
dxdt = -E1*xx/(eta*(1+E1/E2))+(F+ eta/E2*dfdt)/(eta*(1+E1/E2));
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
