Need help writing a for loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Jack Svilms
il 16 Feb 2019
Commentato: Jack Svilms
il 16 Feb 2019
So I was assigned a project where I wrote a function f that takes inputs q, Tc and T and returns a number according to a chemistry equation. The second part of the assignment was to write a program that loops 50 values of T between 0.5 and 1.3 and finds the value of q that minimises the value of f (using fminsearch) at a given T where Tc always = 1. I wouldn't normally use a loop to do this, but we have to here so here's what I have so far which is probably very wrong but I don't really know how to get it to work. We have to plot a graph of the min q values against the T values but my graph comes back blank.
Thanks for the help.
Ti = 0.5;
Tf = 1.3;
nT = 50;
for iT = 1:nT
T = Ti + (Tf - Ti)*iT/(nT-1);
Te(iT) = T;
qmin = fminsearch(@(q) f(q,1,T), T);
end
plot(T,qmin)
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!