Is there any solution to my problem ?please help me.
4 views (last 30 days)
Show older comments
The goal is to solve the following system of 2 non linear equations in simulink. We have to find x and y such as:
A*x^P1+2*y^2-5*x+7*y-40=0
3*x^2-y^2+4*x+B*y^P2-28=0
where A, B, P1 and P2 are variables.
Before going to simulink I wrote the folloing m-file
function F = anothertrial(xy,A,B,P1,P2)
F=[A*xy(1)^P1+2*xy(2)^2-5*xy(1)+7*xy(2)-40;3*xy(1)^2-xy(2)^2+4*xy(1)+B*xy(2)^P2-28]
and I have saved this m-file under the name: anothertrial.m
My simulink model is containing two parts (two groups of blocks). In the first part, complicated calculations are done for the calculation of A, B, P1 and P2 and each one of them is sent to the workspace through the use of 4 blocks "to workspace" and each time the name of the variable in the "to workspace" block has been changed to A, B, P1 and P2 successively.
The second part of my model is containing only 3 blocks:the first block is "from workspace" and the name of the data of this block has been changed to xy0. The output of this block is connected to a "matlab function" block of which the matlab function space has been filled with the expression:
fsolve(@(XY)anothertrial(xy,A,B,P1,P2),XY0)
and finally the output of this block is connected to "display" block.
before starting the simulation I typed in the command window the value of the guess for the fsolve function:
XY0=[2 3]
The idea is to run a simulation of the model in which the simulation of the two parts of the model is done simultaneously in this way: The values of A, B, P1 and P2 are calculated in the first part of the model and sent to the workspace, then when A, B, P1 and P2 become available in the workspace they are used by the "matlab function" block (the fsolve block) to solve the given system of non linear equations.
But
When the model is run the simulation is stopped and error messages are generated.
Note:
1/when the first part of the model is put in an independent model and run the values of A,B,P1 and P2 are calculated and displayed on the "display" blocks.
2/When the second part of the model is put in an independant model and run, after typing in the command window the values of A, B, P1, P2 and the guess XY0, the system of the non linear equations is solved and values for X and Y are displayed in the "display" block.
It seems that when the simulations of the two parts of the model are run simultaneously the values of A, B, P1 and P2 are not accessible to the "fsolve function" block in the second part.
Please is there any solution to my problem????
Help me please.
1 Comment
the cyclist
on 14 Feb 2012
I suggest you change the title of your post to something more meaningful, to better entice people knowledgeable about the specific problem you are trying to solve.
Answers (2)
Ilham Hardy
on 14 Feb 2012
On Simulink, AFAIK, the workspace data only available after the simulation ends. It means the first and second note are correct. The third note however cannot be executed since the parameters for second block (submodels) are not available yet.
Instead of using 'To Workspace' and 'From workspace' blocks, you can directly connect the ouputs of first submodel into second submodel inputs. Try use 'Bus Creator' under the 'Signal Routing' on Simulink (for neatness).
HTH, IH
0 Comments
Ryan G
on 15 Feb 2012
Another alternative, since that is a relatively small function, would be to recreate that function using Simulink blocks and create a subsystem. This will avoid the need for a MATLAB function block.
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!