Plotting a curve with two equations

5 views (last 30 days)
Greetings,
I have a simple question.
I need to plot a curve based on 2 equations, where the plot follows the 1st equation except for the period 10.5<x<11, where the plot is based on a 2nd equation
This is what i'm doing
phi = 0.003;
vx = 0.003;
k = 32*0.4244;
d1 = 8930;
rho1 = 1.7*10^-8;
c1 = 385;
a1 = 0.003862;
d2 = 2700;
rho2 = 3.78*10^-8;
c2 = 893;
a2 = 0.0039;
x = load('file.txt');
x = x(:,1);
r1 = load('file.txt');
r1 = r1(:,2);
I1 = r1*pi*(phi^2)/4;
if (x>10.5) & (x<11)
T1 = k*(I2.^2)*rho2./(pi*pi*d2*c2*vx*(phi^3)-k*(I2.^2)*rho2*a2);
else
T1 = k*(I1.^2)*rho1./(pi*pi*d1*c1*vx*(phi^3)-k*(I1.^2)*rho1*a1);
end
f1=figure(1);
clf;
get(f1);
set(f1,'Units','centimeters','Position',[3 3 24 14]);
set(f1,'Name','Real(Z)');
axes1 = axes('Parent',f1,'FontWeight','bold','FontSize',14,'Ygrid', 'on','grid', ':','Position',[0.15 0.2 0.8 0.7]);
set(gcf,'Color',[1,1,1]);
box on;
hold on;
axis([0, 16, 0, 400]);
set(gca,'XTick',[0:1:16], 'YTick', [0:50:400]);
plot([2000,3000], [2000,3000], '-g','LineWidth',1.6,'Marker','none');
hold on
plot(x, T1, '-g','LineWidth',2,'Marker','none', 'Markersize', 5);
hold on
I know this should be very basic stuff and I apologize for not taking the time to do a proper research on the matter.

Accepted Answer

Star Strider
Star Strider on 21 Sep 2014
I cannot run your code (I don’t have ‘x’ and ‘r1’), and I am not certain what is not working in your code, but one problem seems obvious: ‘T1’ does not seem to be a function of either ‘x’ or ‘r1’ between 10.5 < x < 11. I don’t see that ‘I2’ is defined anywhere.
I would:
1. Define I2 (that probably needs to be a vector);
2. Wrap the T1 calculation in a loop:
for k1 = 1:length(x)
if (x(k1)>10.5) & (x(k1)<11)
T1(k1) = k*(I2(k1).^2)*rho2./(pi*pi*d2*c2*vx*(phi^3)-k*(I2(k1).^2)*rho2*a2);
else
T1(k1) = k*(I1(k1).^2)*rho1./(pi*pi*d1*c1*vx*(phi^3)-k*(I1(k1).^2)*rho1*a1);
end
end
I cannot be certain that this will solve whatever the problem is, but it seems that it might get you started. This could be made more efficient (without the loop), but the interval between 10.5 < x < 11 and the change from ‘I1’ to ‘I2’ in that interval makes the loop the easiest option.
  2 Comments
Pedro
Pedro on 21 Sep 2014
Thanks, Star Strider, it did solve my problem. By the way, the I2 was a typo, it should have been I1. Cheers.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!