solving a quartic using simulink

4 次查看(过去 30 天)
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.

采纳的回答

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

请先登录,再进行评论。

更多回答(1 个)

Sulaymon Eshkabilov
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.

类别

Help CenterFile Exchange 中查找有关 Manual Performance Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by