How to set an array in matlab?
1 次查看(过去 30 天)
显示 更早的评论
Hi, I ma trying to plot a graph Re as a function of k. But before that, I need to input A,B and v to calculate a,b,c,d,alpha and beta.
Below is my code:
clear all
A1=input('What is the value of A ','s');
B1=input('What is the value of B ','s');
V1=input('What is the value of V ','s');
K1=input('What is the value of K ','s');
A=str2num(A1);
B=str2num(B1);
K=str2num(K1);
V=str2num(V1);
a=B; %%%formula for a
b=(A+sqrt(A.^2 - 4*(B.^2)))/(A-sqrt(A.^2 - 4*(B.^2))); %%%formula for b
c= -2*B; %%%formula for c
d=-2*A/(A-sqrt(A.^2 - 4*(B.^2))); %%%formula for d
array(K);
alpha=(a+d-K.^2).^2 - (K.^2)*(V.^2)-4*(a*d - b*c - d*(K.^2))
beta=2*K*V*(K.^2 - a + d)
re=1/2 *(a+d-K.^2+ sqrt((1/2 *((sqrt((alpha).^2 + (beta).^2))+ alpha))))
%A plot Re as a function of k
K=(0:0.01:1);
y=re;
figure;
plot(K,y,'r');
title('Re as a function of k', 'fontsize', 10);
xlabel('K');
ylabel('Re');
0 个评论
回答(1 个)
A Jenkins
2014-2-17
I'm not really sure what your question is. Are you trying to do this?
clear all
A1=input('What is the value of A ','s');
B1=input('What is the value of B ','s');
V1=input('What is the value of V ','s');
K1=input('What is the value of K ','s');
A=str2num(A1);
B=str2num(B1);
K=str2num(K1);
V=str2num(V1);
a=B; %%%formula for a
b=(A+sqrt(A.^2 - 4*(B.^2)))/(A-sqrt(A.^2 - 4*(B.^2))); %%%formula for b
c= -2*B; %%%formula for c
d=-2*A/(A-sqrt(A.^2 - 4*(B.^2))); %%%formula for d
%array(K);
K=(0:0.01:1);
alpha=(a+d-K.^2).^2 - (K.^2)*(V.^2)-4*(a*d - b*c - d*(K.^2))
beta=2.*K.*V.*(K.^2 - a + d)
re=1/2 *(a+d-K.^2+ sqrt((1/2 *((sqrt((alpha).^2 + (beta).^2))+ alpha))))
%A plot Re as a function of k
y=re;
figure;
plot(K,y,'r');
title('Re as a function of k', 'fontsize', 10);
xlabel('K');
ylabel('Re');
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!