Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Solve for y when it cant figure it out in y=f(x) form. Need to solve in matlab function block in simulink
조회 수: 2 (최근 30일)
이전 댓글 표시
X= [ 0.024 0.055] ;
% Equation need to solve
0.364*(Y-0.024)-√(0.00060025-(0.009+Y)^2) = 0.048*(X-0.024)-0.07603
댓글 수: 0
답변 (1개)
Stephan
2018년 7월 18일
Hi,
you can do so:
syms x y
% Starting Point
fun = 0.364*(y-0.024)-sqrt(0.00060025-(0.009+y)^2) == 0.048*(x-0.024)-0.07603;
% Equation y=f(x)
f(x) = rhs(isolate(fun,y))
% Function Handle for calcualtions in Matlab
fun_handle = matlabFunction(f)
% Matlab function Block for use in Simulink
new_system('my_system')
open_system('my_system')
matlabFunctionBlock('my_system/my_block',f)
This gives you 3 different solutions:
1. you get the equation in the format y=f(x)
f(x) =
(1092*x)/70781 + (- 36000000*x^2 + 97755000*x - 32131815832268837361321925/576460752303423488)^(1/2)/141562 - 4239293/141562000
2. You get a function handle to work with in Matlab
fun_handle =
function_handle with value:
@(x)x.*1.542786906090618e-2+sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7).*7.064042610305025e-6-2.994654638956782e-2
3. you get a matlab function block for the use in simulink, which i could not test, since i did this in Matlab online.
To do this the symbolic math toolbox is required.
Best regards
댓글 수: 2
Walter Roberson
2018년 8월 23일
For that particular function, you can use
[x.*1.542786906090618e-2-sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7)./1.41562e5-2.994654638956782e-2;
x.*1.542786906090618e-2+sqrt(x.*9.7755e7-x.^2.*3.6e7-5.573981525e7)./1.41562e5-2.994654638956782e-2]
This gives the two roots,
Be careful: the results are complex outside of
6517/4800 - (49*70781^(1/2))/24000
(49*70781^(1/2))/24000 + 6517/4800
so unless you are certain that the inputs will be in that range, you might need to code calls to complex() in the expression in order for Simulink not to complain about incompatibilities.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!