Need help writing a for loop

조회 수: 1 (최근 30일)
Jack Svilms
Jack Svilms 2019년 2월 16일
댓글: Jack Svilms 2019년 2월 16일
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)

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 16일
assign to qmin(iT)
plot(Te,qmin)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by