Clear Filters
Clear Filters

How to set an array in matlab?

2 views (last 30 days)
Alex
Alex on 17 Feb 2014
Edited: A Jenkins on 17 Feb 2014
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');

Answers (1)

A Jenkins
A Jenkins on 17 Feb 2014
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 Comments
Alex
Alex on 17 Feb 2014
Edited: Alex on 17 Feb 2014
Sorry of poor explaining. All I want to do is plot the graph a graph of "Re" as a function of "K". First, I need to input the values of A1,B1 and V1 to calculate a,b,c,d, alpha and beta.
But perhaps the problem is that I have already defined K as a scalar, and then Re becomes a scalar. Then I redefine K as a vector, but I do not think that matlab will recompute Re so y just becomes the scalar.
The codes above is my present works, it works fine until the code attempt to plot the graph.
A Jenkins
A Jenkins on 17 Feb 2014
Edited: A Jenkins on 17 Feb 2014
My version of the code (pasted above) does this:
Is this what you want?
(I'm not sure why you are accepting K as an input, as far as I can tell, you could just remove that code.)

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!