How to plot these function plesa help

Hello.
I tried almost everything, but with no succsess. Maybe anyone knows and can share matlab code to plot these function: f(x) = (4 - 2.1*x1^2 + x1^4/3)*x1^2 + x1*x2 + (-4 + 4*x2^2)*x2^2
Thank you

 Réponse acceptée

Mischa Kim
Mischa Kim le 17 Juin 2015
Joe, you could use
[x1,x2] = meshgrid(0:0.5:10,0:0.5:10);
f = (4 - 2.1*x1.^2 + x1.^4/3).*x1.^2 + x1.*x2 + (-4 + 4*x2.^2).*x2.^2;
surf(x1,x2,f)

5 commentaires

Joe Gani
Joe Gani le 17 Juin 2015
thank you I fugured these solution too but why the function is not like these made with WOLFRAM ALPHA: http://www.wolframalpha.com/input/?i=plot+y+%3D+%284+-+2.1*x%5E2+%2B+x%5E%284%2F3%29%29*x%5E2+%2B+x*z+%2B+%28-4+%2B+4*z%5E2%29*z%5E2
It is a slightly different function (see 4/3) and a different range. Try
[x1,x2] = meshgrid(0.9:0.1:1.4,-1:0.1:1);
f = (4 - 2.1*x1.^2 + x1.^(4/3)).*x1.^2 + x1.*x2 + (-4 + 4*x2.^2).*x2.^2;
surf(x1,x2,f)
Joe Gani
Joe Gani le 17 Juin 2015
Thank you I understand but these answer made new question. Why I get an error if i change bounds in meshgrid I want to draw in range -64 to 64 on x1 and x2 axes.
Thank you for your help.
The function has x1^(4/3) . When x1 is negative, the result is complex.
Note that x1^(4/3) is not the same thing as (x1^4)^(1/3) and is potentially different again from (x1^(1/3))^4; just as x1^(1/2) is not the same as (x1^2)^(1/4) . Taking a number to a fractional power requires choosing one root, not hunting through the integer multiples of the exponent to find one that will make the root real-valued.
Perhaps you want,
f = (4 - 2.1*x1.^2 + (x1.^4).^(1/3)).*x1.^2 + x1.*x2 + (-4 + 4*x2.^2).*x2.^2;
but be aware that might not match the formula on the paper.
if helps the function in matlab code is:
y = (4-2.1.*x1.^2+x1.^4./3).*x1.^2+x1.*x2+(-4+4.*x2.^2).*x2.^2;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by