How can I substitute a function into another equation to plot the answer?
4 views (last 30 days)
Show older comments
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 Comment
Rong
on 29 Oct 2023
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.
Accepted Answer
Matt Fig
on 29 Nov 2012
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 Comments
Rong
on 29 Oct 2023
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!