how to create a changing variable for fsolve?

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.1: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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Jul. 2012
Bearbeitet: Walter Roberson am 6 Jul. 2012

0 Stimmen

function Result = f(YourArray)
persistent iteration_number
if isempty(iteration_number); iteration_number = 0; end
iteration_number = iteration_number + 1;
if iteration_number > numel(YourArray);
Result = [];
iteration_number = []; %reset for next cycle
return;
end
Result = some expression in YourArray(iteration_number)
end
Please also read the documentation for fsolve() as you cannot pass in parameters the way you do. Please see the section about parameterizing the function.

5 Kommentare

Hana
Hana am 6 Jul. 2012
Bearbeitet: Hana am 6 Jul. 2012
thanks for your help! i used a for loop to describe the changes on the variable, but the old results gets overwritten everytime it starts a new loop. is there any possibilities to get updated the values from each loop? or do i automatically get the updated values when i load the results of each value into simulink? the function in simulink will be called every 0.001s.
best regards
Instead of using a for loop in your MATLAB code, use a MATLAB Function Block at the Simulink level with the appropriate that takes a single input (or no input at all) and outputs a single result, controlling invocations of the block at the Simulink level, either via the Simulink equivalent of a for loop or by taking a signal as input where the signal value indicates the parameter to use for fsolve()
Hana
Hana am 6 Jul. 2012
i think i understood the method you are suggesting, but i'm having trouble realizing it. i found the function-call-generator in simulink, but i'm not sure how to call the fsolve from there, since i can't write the fsolve into the matlab function directy and coder.extrinsic only calls functions and not scripts...
Write a Level 2 S function if necessary.
There is a lot about Simulink that I have not put together mentally yet, as I do not have access to it myself.
Hana
Hana am 8 Jul. 2012
thank you, i will try that. &thanks for taking time answering my questions :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by