%it is just a example i want to know if there are multiple number of say x with other constant say a and b. Is it possible to plot graph between x and y. I am working with similar code that i wrote below but graph is not showing. Clc; Close all; Clear all; A=5; B=6; X=4,9,56,33 Y=(a+b)/x Plot (X,Y)

 채택된 답변

Star Strider
Star Strider 2020년 2월 11일

0 개 추천

Try this:
A=5;
B=6;
X = [4,9,56,33];
Y=(A+B)./X;
figure
plot (X,Y)
Use element-wise operations (the (.) operator) in the division. See Array vs. Matrix Operations for an extended discussion.

댓글 수: 3

rajdeep singh
rajdeep singh 2020년 2월 11일
Thank you sir, but it is working perfectly for scalar.
Here is the real code
A=31*10^6; B=7.625*10^-43; C=8.38*10^-34; D=700; f=[23.27,24.72,33.18,34.63,44.08,44.54,44.99] i= arrayfun(@(z) ((2B*z^3)/(A*(exp((B*z))-1))),f) plot (f,i)
I tried arrayfun but still not working.
rajdeep singh
rajdeep singh 2020년 2월 11일
I mean / instead of ./ Is also working perfectly. For single valued x.
The arrayfun call (essentially a slow for loop) is not necessary here. Vectorised MATLAB commands make explicit loops and other such operations unnecessary.
If I understand correctly what you want to do, this should work:
A=31E6;
B=7.625E-43;
C=8.38E-34;
D=700;
f=[23.27,24.72,33.18,34.63,44.08,44.54,44.99];
zfcn = @(z) (2*B*z.^3)./(A*exp(B*z)-1);
figure
plot(f, zfcn(f))
grid
This works for vector ‘f’. Again, note the use of element-wise operations in the exponentiation and division. You can assign the output of ‘zfcn(f)’ to an intermediate variable if you wish. I do not here, and simply use it as an argument to the plot function.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

fred  ssemwogerere
fred ssemwogerere 2020년 2월 11일

0 개 추천

While your question may not be so clear, from my understanding, you are trying to find a vector,"Y" from a vector of "X" values. Try this:
A=5; B=6; X=[4,9,56,33];
% your vector "Y". From this you can proceed with your plot
Y=arrayfun(@(z) (A+B)/z, X);

댓글 수: 2

rajdeep singh
rajdeep singh 2020년 2월 11일
clc; close all; clear all;
A=31*10^6; B=7.625*10^-43; C=8.38*10^-34; D=700; f=[23.27,24.72,33.18,34.63,44.08,44.54,44.99] i= arrayfun(@(z) ((2B*z^3)/(A*(exp((B*z))-1))),f) plot (f,i)
rajdeep singh
rajdeep singh 2020년 2월 11일
Not working

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2020년 2월 11일

댓글:

2020년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by