フィルターのクリア

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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by