Need help writing a for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!