i want fsolve to calculate the output for different uc each time (increasing uc by 0.001 each time). each output from fsolve should be sent to a simulink model seperatly. so i set a loop to do so, but i believe that at the currenty constellation (if it will work)will just calculate 1000 different values? is there a way to send out the values seperately?
if not, how can i create a parameter uc. that goes from 0 to say 1000? i tried uc=0:0.001:1000, but again, the demension doen’t seem to fit.
how do i create a function that takes the next element of a vector/matrix each time the function is called?
best regards
The general approach to iterating over an array of values and feeding them one-by-one into a series of evaluations of a function follows this form:
See how each call to
funcincludes the current value ofix? On the first iterationix==0, on the nextix==0.1and so forth. You should be able to adapt this to your needs; in your code the loop index (which you calli) is not used inside the loop.Now some un-asked-for criticism of your code. The lines
do not change as the loop iterations advance; they always return the same values whatever the value of the loop iterator (
iin your code) may be. It is pointless including them inside the loop.Leaving them inside the loop may even be a waste of a lot of time if Matlab decides to calculate them at every iteration. I’m not sure what Matlab does in this case, it may be smart enough to figure out that these values don’t change at each iteration, but even if it does it is bad programming practice to write your code this way; lift constant expressions such as these out of loops.
It’s not clear from the fragment you’ve posted why you have defined
y,uandycat all, they’re not used anywhere; perhaps they’re used in other parts of your program.