Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Mikhos
Mikhos le 29 Nov 2012
Commenté : Rong le 29 Oct 2023
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 commentaire
Rong
Rong le 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.

Connectez-vous pour commenter.

Réponse acceptée

Matt Fig
Matt Fig le 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 commentaires
Mikhos
Mikhos le 5 Déc 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 le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by