Quartic solver using Embedded matlab function
이전 댓글 표시
Hello,
I have used an embedded matlab function in simulink to solve a general quartic. Following is the code that I have written in this block
function t = my_quartic (C1,C2,C3,C4,C5)
%eml.extrinsic('p');
p=[C1 C2 C3 C4 C5];
t=roots(p);
%function t=roots(p)
I have used constant blocks to provide the values of C1=3,C2=6,C3=-123, C4=-126 AND C5=1080. I have used the "to file" block as a sink to store the values of t.
Now for the values of coeficients shon above, the roots of t should come out to be 5,3,-4,-6. But when I run the simulation, I get the following error: Data 't' (#23) is inferred as a variable size matrix, while its specified type is something else.
I have tried changing the properties of t in the editor, but its not working. Can someone help me on this? I will be greatly thankful for any comments.
Best Regards, Amir
채택된 답변
추가 답변 (1개)
Walter Roberson
2011년 9월 1일
Before the t = roots(p) call, add the line
t = zeros(1,4);
Yes, this will assign a value to t and then overwrite it on the very next line, but doing this will give enough information to the embedded coder to know the size to expect for t.
By the way: why are you specifying p to be extrinsic, as it is not an external function? I could understand if you had said that 'roots' was extrinsic ?
댓글 수: 3
Zealous131
2011년 9월 1일
Walter Roberson
2011년 9월 1일
Ummm, I'm not sure, but as an experiment, try changing the last line to
t(1:4) = roots(p);
Walter Roberson
2011년 9월 1일
By the way, I am not certain that you need to construct p explicitly. I think you _might_ be able to use
function t = my_quartic (C1,C2,C3,C4,C5)
t = zeros(1,4);
t(1:4) = roots([C1,C2,C3,C4,C5]);
Though it would not surprise me if it turned out that you needed to declare roots as extrinsic at some point.
카테고리
도움말 센터 및 File Exchange에서 Signal Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!