필터 지우기
필터 지우기

How can I substitute a function into another equation to plot the answer?

조회 수: 1 (최근 30일)
Mikhos
Mikhos 2012년 11월 29일
댓글: Rong 2023년 10월 29일
I have an equation: r =1/16( a^4 + a^8/f(a) + f(a) )
of which f(a) = (2048 + 128a^6 + a^12 + sqrt(16384 + 2048a^6 + 80^12 + a^18))^1/3
I need to use MatLab to sub f(a) into r and thus plot r (and then continue to do more such substitutions in my model) however we havent been taught very much of Matlab and the more examples i find the mos confused and frustrated i get when things dont work.
I managed to get the following code so far and it brings up the error message below that. I think it might just be syntax or a command I dont know but appart from that i am stuck.
please could someone help me in this respect?
Code
a= sym('a')
r = sym('1/16.*(a.^4 + a.^8./F + F')
subs(r,'F','(2048 + 128.*a.^6 + a.^12 + sqrt(16384 + 2048.*a.^6 + 80.*.^12 + a.^18)).^1/3')
answer shown:
a =
a
??? Error using ==> sym.sym>convertExpression at 2547
Error: 'expression' expected [line 1, col 6]
Error in ==> sym.sym>convertChar at 2458
s = convertExpression(x);
Error in ==> sym.sym>convertCharWithOption at 2441
s = convertChar(x);
Error in ==> sym.sym>tomupad at 2195
S = convertCharWithOption(x,a);
Error in ==> sym.sym>sym.sym at 111 S.s = tomupad(x,'');
  댓글 수: 1
Rong
Rong 2023년 10월 29일
Update: in later versions, plot functions are separated into plot and fplot. Use fplot to plot a function, for instance:
syms x
p=@(x) ((1000/9*exp(x))/(exp(x)/9+1))
fplot( p(x))
if plot is instead used, the following error occurs:
Data must be numeric, datetime, duration, categorical, or an array convertible to double.

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

채택된 답변

Matt Fig
Matt Fig 2012년 11월 29일
f = @(a) (2048 + 128*a.^6 + a.^12 + sqrt(16384 + 2048*a.^6 + 80^12 + a.^18)).^(1/3);
r =@(a) (1/16)*( a.^4 + a.^8./f(a) + f(a) );
x = 0:.01:5;
plot(x,r(x))
  댓글 수: 2
Mikhos
Mikhos 2012년 12월 5일
Thanks so much for your help. Do you know how i can get it to show "r"? As in the full version with f(a) subbed in already.
Rong
Rong 2023년 10월 29일
Update: in later versions, plot functions are separated into plot and fplot. Use fplot to plot a function, for instance:
syms x
p=@(x) ((1000/9*exp(x))/(exp(x)/9+1))
fplot( p(x))
if plot is instead used, the following error occurs:
Data must be numeric, datetime, duration, categorical, or an array convertible to double.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by