필터 지우기
필터 지우기

Array as input for symbolic function

조회 수: 1 (최근 30일)
cdlapoin
cdlapoin 2022년 2월 27일
댓글: cdlapoin 2022년 2월 27일
this is an quation for the Mach number as a function of location and area ratio
so I create an array of area ratios and want to examine M
A_ratio = (0:1:100);
gamma = 1.4;
syms M
eq1 = A_ratio == ((gamma+1)/2)^((gamma+1)/(2*(gamma-1)))*((1+(gamma-1)/2*M^2)^((gamma+1)/(2*(gamma-1)))/M)
eq1 = 
var = vpa(eq1)
var = 
double(var)
ans = 1×101
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
here the symbolic output of vpa looks correct (non-zero), but when I try to change back from symbolic to numeric array the result is all zeros. is double() the wrong command for this? I am referencing: https://www.mathworks.com/help/symbolic/conversion.html
is there a smarter way to do this?

채택된 답변

Torsten
Torsten 2022년 2월 27일
gamma = 1.4;
syms A_ratio M
eq1 = A_ratio == ((gamma+1)/2)^((gamma+1)/(2*(gamma-1)))*((1+(gamma-1)/2*M^2)^((gamma+1)/(2*(gamma-1)))/M);
sol = solve(eq1,M);
solnum = subs(sol,A_ratio,1) %e.g.
  댓글 수: 1
cdlapoin
cdlapoin 2022년 2월 27일
Thank you,
I didn't expect to get 6 roots, and none of them matched what I know about how the output should look. In the end it was because of a missing (-) sign in my definition of eq1. Once that was corrected I could easily see that the real part of the first root was the correct value I was looking for.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by