Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Rong
Rong el 29 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Matt Fig
Matt Fig el 29 de Nov. de 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 comentarios
Mikhos
Mikhos el 5 de Dic. de 2012
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 el 29 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by