Need help writing a for loop

3 views (last 30 days)
Jack Svilms
Jack Svilms on 16 Feb 2019
Commented: Jack Svilms on 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)

Accepted Answer

Walter Roberson
Walter Roberson on 16 Feb 2019
assign to qmin(iT)
plot(Te,qmin)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!