solving a quartic using simulink

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Aug 2011
MuPad provides matlabFunction() that can generate MATLAB code. You would then use a MATLAB Block if I recall.
  2 Comments
Amir Khan
Amir Khan on 8 Aug 2011
Thanks Walter! Can you tell me how can I do that? Im new to it and struggling with it

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 4 May 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.

Categories

Find more on Manual Performance Optimization 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!