solving a quartic using simulink
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Amir Khan
am 7 Aug. 2011
Beantwortet: Sulaymon Eshkabilov
am 4 Mai 2019
Hi, I have a general quartic equation. I have solved it in maple and Mupad both but I want to create a block in simulink so that when I provide different values of the coefficients to the block, it gives me the solution of that quartic equation for that particular set of coefficients. Can somebody help? Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Aug. 2011
MuPad provides matlabFunction() that can generate MATLAB code. You would then use a MATLAB Block if I recall.
2 Kommentare
Weitere Antworten (1)
Sulaymon Eshkabilov
am 4 Mai 2019
Hi,
Here are the steps to model a simple quadratic equation:
% Step 1. Drag and drop three [Constant] blocks into your Model window for a, b, c whose values you can define directly in each block, or via workspace (MATLAB command window), or via Model properties:==> File ->Model Properties -> Callbacks ->IntitFcn: a = ???; b= ???; c =???;
% Step 2. Drag and drop [Display] block into your Model window.
% Step 3. Drag [MATLAB Function] block and double click on it. Write the following two lines of code in the opened M-file editor and save it:
function y = fcn(a, b, c)
y=roots([a, b, c]);
% Step 4. When you save your fcn() file - M-file editor saves your Simulink model. Now, your [MATLAB Function] block will have three input ports for [a], [b],[c], respectively.
% Step 5. Connect three [Constant] block with the [MATLAB Function] block and output port of it with [Display] block. Now the model is complete, BUT it has a problem with the output data size.
% Step 6. Click on Model Explorer (Ports and Data Manager) -> [MATLAB Function] -> y Output -> Enter: 2 in size and put a tick mark on Variable Size option -> hit [Apply].
% Step 7. Hit [Run] and have fun ... :) . See the screenshot of the complete model and its results shown here.
% Note: Solver of your model has to be set at "Fixed Step". By default the Simulink model solver is set at "Variable Step" solver option.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Manual Performance Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!