electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Matlab How to do z=f(x,y)?


Post new topic  Reply to topic    EDAboard.com Forum Index -> Electronic Elementary Questions -> Matlab How to do z=f(x,y)?
Author Message
davyzhu



Joined: 23 May 2004
Posts: 521
Helped: 3
Location: oriental


Post18 Mar 2006 14:15   

Matlab How to do z=f(x,y)?


Hi all,

I want to do
X=[-5:0.1:5];
Y=[-5:0.1:5];
Z=log(exp(X)+exp(Y));

I want to get Z as a 101*101 (n*n) vector
But the Matlab give Z as a 1*101 (1*n) vector.

How to get Z 101*101 vector without "for loop"?

Best regards,
Davy
Back to top
mimomod



Joined: 25 Jan 2006
Posts: 109
Helped: 15


Post18 Mar 2006 19:35   

Matlab How to do z=f(x,y)?


Hi davyzhu,

I am not really clear what you need for Z, but i just guess that you want to have every combination of X and X as parameter for Z. Then try:

X=[-5:0.1];
Y=[-5:0.1];
Z=log(exp(kron(ones(length(X),1),X).')+exp(kron(length(Y,1),Y)));

best

Added after 5 minutes:

sorry....there is some mistake....it should have been...

X=[-5:0.1];
Y=[-5:0.1];
Z=log(exp(kron(ones(length(X),1),X).')+exp(kron(ones(length(X),1),X).') );

Added after 15 minutes:

Sorry moderator, still there is small mistake....it should have been...

X=[-5:0.1:5];
Y=[-5:0.1:5];
Z=log(exp(kron(ones(length(X),1),X).')+exp(kron(ones(length(Y),1),Y)) );

i.e. the second exp() is for Y and also there is no transpose operator.

best
Back to top
Google
AdSense
Google Adsense




Post18 Mar 2006 19:35   

Ads




Back to top
davyzhu



Joined: 23 May 2004
Posts: 521
Helped: 3
Location: oriental


Post19 Mar 2006 3:15   

Matlab How to do z=f(x,y)?


Hi,

I have solved it Smile

X=[-5:0.1:5];
Y=[-5:0.1:5];
[Xnew Ynew] = meshgrid(X,Y);
Z=log(exp(Xnew)+exp(Ynew));

Regards,
Davy
Back to top
neils_arm_strong



Joined: 05 Jan 2006
Posts: 274
Helped: 20


Post19 Mar 2006 9:44   

Matlab How to do z=f(x,y)?


more simple than above is..


[X,Y]=meshgrid(-5:0.1:5);
Z=log(exp(X)+exp(Y));
this will work fine.
also try
surf(X,Y,Z); in the above code at the end.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Electronic Elementary Questions -> Matlab How to do z=f(x,y)?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Sample the recorded sound in matlab...How ? Using MATLAB. (3)
How I use tektronix matlab waveform in MATLAB simulink? (2)
MATLAB: how to link matlab with opnet (1)
How to do OK=(IN==OUT)?1:0; in Matlab? (3)
how to convert c to matlab (3)
how to implement E[x] in matlab? (5)
How can filter in Matlab (3)
How do I convert my MATLAB files to C? (7)
How to do parallel operation in Matlab? (4)
How to convert Matlab to HDL? (5)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS