Creating fun structure in a loop
Show older comments
Hi,
as a bloody beginner i cant figure out on how i could write a loop, which should sum up a specific term in a symbolic way.
I need
fun = @(x)x(1)*(1 - exp(-xdata/x(2))) + x(3)*(1 - exp(-xdata/x(4))) + x(5)*(1 - exp(-xdata/x(6))) + x(7)*(1 - exp(-xdata/x(8))) - ydata;
but i want to write a loop, so that the term
x(1)*(1 - exp(-xdata/x(2)))
is added as often as i want.
I need it for thermal calculation for a changeable amount of RC-terms in the Foster model, which is later tranformed into the Cauer model.
My code in general:
prompt = {'Enter the desired amount of RC-Terms'};
dlgtitle = 'RC-Terms';
definput = {''};
opts.Interpreter = 'tex';
answer = inputdlg(prompt,dlgtitle,[1 40],definput,opts);
amount = str2double(answer{1});
x0= 1:1:2*amount; % starting position for fit algorithm
for i=1:2:2*amount
x0(1,i)=0.1;
for k=2:2:2*amount
x0(1,k)=1;
end
end
options = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt');
fun= %this is, where the loop should be for a variable amount of Rc terms
x = lsqnonlin(fun,x0,[],[],options);
...
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!