how to add a plot function in ionic with higcharts? - ionic-framework

so i'm doing an app in ionic 2 like geogebra so for example if i want to graph a lineal or quadratic equation i will use the function 'y = mx + b' and the user can modify only 'm' and 'b' and show this graphic.
so do you have any ideas that can show me.?
I'll be eternally grateful (:

Related

How to simulate a simple equation in MATLAB?

I have this equation that I need to simulate and then plot Y in terms of X. I use the following code to do this but at the end it gives me this straight line as the graph which clearly isn't what I expect to see:
r = .5;
beta = 5;
b = 1;
N = 10;
K = 15;
p = .7:.05:5.7;
l_0 = 0:.01:1;
p*K.*(1-(l_0/r)) == 1./((N*beta*(b^beta)./((beta-1)*l_0))).^(1/(beta-1));
plot(p,l_0,'b*-')
I need to see how l_0 varies as p varies by simulating the equation and using the parameter values above.
This is the graph that I get when I run the code:
I somehow guess that there's something wrong with the way I've set the values for p and l_0 but I'm almost new to MATLAB and don't know how to fix it. I'd appreciate if any one could help me to find out where I'm making mistake(s).
If you view the MATLAB Documents page for the colon operator, you will see that : acts as a unit vector. Basically, it creates a linear space from j to k, by i intervals. So the graph as it is currently displayed is correct. It displays two linear vectors.
However, what you may want to change is the aspect ratio of the graph. Right now, your aspect ratio custom fits your data (which it sounds like you do not want). Look under the axis style section in the MATLAB Documentation for axis limits and aspect ratios to see what style you want your plot in.
Hope this helps you out.
The graph/plot that you are showing here is seems to work only with this:
p = .7:.05:5.7;
l_0 = 0:.01:1;
plot(p,l_0,'b*-')
YES! that is it. All the other things that you have written are playing no role (it seems).
basically you have not evaluated / populated p with l_0 so if you want to see that then
keep p blank
Rearrange your equation with only p at LHS.
Let l_0 handle/fill the values of p.
Now if you only want to see the curve/plot between p = .7:.05:5.7;, then you can check how to do that with the axes property or simply zoom-in/out.
Hope this helps

plotting sin(x) graph in Matlab - strange results

Hi I'm trying to plotting graphs in Matlab and I getting strange results:
i should do graphs of y=asin(bx+c)
when a,b,c changing from graph to graph..
but as u can see when I'm changing the 'b' value to a big one
the graph in figure app become strange.
and one of the causes that make the graphs strange is the 'N' value in the matlab function: x=linspace(x0,xt,N)
why for example when I'm changing N to 200 the graph going crazy?
what exactly 'N' doing maybe i didn't get it :(
so here is my code, the problem is in 'figure 4' (section 'c'), the graph there is not looking like sin(x)
while in figure1,2,3 it was all good.
[when offering me a solution, please consider i need the graph with 3 full cycles].
code:
%------a------%
vm1=20;
vm2=41;
vm3=79;
f=44;
w=2*pi*f;
t=linspace(0,6*pi,120); %6pi for 3 cycles
v1=vm1*sin(w*t+pi/3);
v2=vm2*sin(w*t-pi/4);
v3=vm3*sin(w*t);
plot(t,v1,t,v2,t,v3);
ylabel('v(t)[V]');
xlabel('t[sec]');
legend('v_1(t)','v_2(t)','v_3(t)');
%-----b-----%
vsum=v1+v2+v3;
figure;plot(t,vsum,'linewidth',2);
ylabel('v(t)[V]');
xlabel('t[sec]');
legend('v_s(t)');
%-----c-----%
f1=200;
w1=2*pi*f1;
f2=200*3.2;
w2=2*pi*f2;
f3=200*4.3;
w3=2*pi*f3;
v1_new=vm1*sin(w1*t+pi/3);
v2_new=vm2*sin(w2*t-pi/4);
v3_new=vm3*sin(w3*t);
figure;plot(t,v1_new,t,v2_new,t,v3_new);
ylabel('v(t)[V]');
xlabel('t[sec]');
legend('v_1new(t)','v_2new(t)','v_3new(t)');
vsum_new=v1_new+v2_new+v3_new;
figure;plot(t,vsum_new,'linewidth',2);
ylabel('v(t)[V]');
xlabel('t[sec]');
legend('v_s(t)');
In your function "y=a * sin(b*x+c)" b changes the period of the sine wave, the time it takes to go one full cycle.
The period: T = 2*pi / b
So if you want to have 3 periods you should calculate T and make sure that your t runs from 0 to 3*T.
t = linspace(0,6*pi/w1,120);

Ordinary Differential Equations in Matlab

Question -
I am working on some matlab code that solves 2 first degree differentials and 2 second order differentials. I am ok with dsolve() but when I want to plot I am currently using ezplot and it is not giving me what I want. I want to produce 1 window with four graphs. I know I would use subplot but I dont know how, an example would be nice. Also I dont know how to make my plots show the importiant area not just a large area. my code is below:
close all % close all figure windows that are open
clear all % clear all the variables currently stored in memory
clc % clear the commands in the command window
%%Problem 1%%%%%
a = (dsolve('Dv = -500*v+5000','v(0)=5'));
display (a)
b = (dsolve('Dx = -2000*x+100','x(0)=-.02'));
display (b)
%%Problem 2%%%%%
c = (dsolve('D2y+2000*Dy+26000000*y-520000000=0','Dy(0)=0','y(0)=5'));
display(c)
d = (dsolve('D2y+100*Dy+2500*y-520000000=0','Dy(0)=20','y(0)=0'));
display (d)
figure
ezplot(a);
axis([0,.01,4,10])
figure
ezplot(b);
axis([0,.01,0,10])
figure
ezplot(c);
axis([0,.01,4,10])
figure
ezplot(d);
axis([0,.01,4,10])
I didn't know until now, but it seems that ezplot only generates data points for "interesting part" of your plot. So if you specify the x-limit that ezplot does not use, you don't see anything. What you need to do is to specify the x-limits in its second argument of ezplot. Then, you can create subplots with standard suplot function, get axis handle, and specify the axis. The plotting part of your code should be like this.
figure
h1=subplot(2,2,1);
ezplot(a, [0,0.01]);
axis(h1,[0,0.01,4,10])
h2=subplot(2,2,2);
ezplot(b, [0,0.01]);
axis(h2,[0,.01,0,10])
h3=subplot(2,2,3);
ezplot(c, [0,0.01]);
axis(h3,[0,.01,4,10])
h4=subplot(2,2,4);
ezplot(d, [0,0.01]);
axis(h4,[0,.01,4,10])

Problems with plotting in Matlab

Hey, I've got a problem plotting a function in Matlab.
I first run this:
format long
f = inline('-x.^2');
for i = 0:10
[I(i+1) h(i+1) tid(i+1)] = trapets(f,0,1,2^i);
end
trunk = I - log(2);
hold on
grid on
plot(log(h),log(trunk),'r+')
t = -7:0;
c = polyfit(log(h),log(trunk),1);
yy = polyval(c,t);
plot(t,yy)
grid off
hold off
koefficienter = real(c)
and after that I run this file:
hold on
plot(h,trunk,'r+:','linewidth',2)
axis([0 0.6 0 0.0014])
Thing is, I don't get any errors, and the plot windows pops up with axes and all, but there is no graph to be found. It's just an empty window with two axes.
Anyone got any ideas?
Edit:
Okay, so I'm new to this site and couldn't find the reply button, so I add a reply here instead.
#woodchips :
I just realized that I hadn't given you all the information for this problem.. Sorry about that, anyhow I would really appreciate it if someone had the time to help me with this, it would seriously make my week.
This is the part I accidentally left out:
function [ I,h,tid ] = trapets(
f,a,b,n )
h=(b-a)/n;
tic; I=(f(a)+f(b));
for k=2:2:n-2
I = I+2*f(a+k*h);
end
for k = 1:2:n-1
I = I + 4*f(a+k*h);
end
I = I * h/3;
tid = toc;
end
Edit 2: So, I think that the graph I'm seeking is actually getting plotted in the first code that I wrote, the problem is that the variabe 'I' is not changing, which I expect it to do, although the variabels 'n' and 'h' do change. If 'I' was working correctly, I would probably get the right graph (hopefully). Any ideas, anyone?
Unfortunately the home computer I had with Matlab on it died the other day so I can't test anything. First thing I can think of if to simply run step by step through the code and see if the results of the math are what you are expecting. For instance Matlab was primarily made and runs as a matrix calculator if I recall correctly. As such most of the simple math doesn't function as it would punching it in a calculator. An example would be that 2^i needs to be 2.^i to operate correctly in some cases. Same with .* and ./ to use the singular scalar verses the matrices math.
The best way to find out what is going wrong is to iterate through the math a few times to ensure that it is being performed as expected. Once that is verified then you can move on to looking at plotting formatting.

problem im motion control with MATLAB

i have a problem in motion control in matlab
imagine a four bar linkage mechanism like this.as you you know in an ordinary 4 bar linkage we have 2 fix points but here we have just one & the second one it fixed to a pinion (small gear).we have the ratio of gears so we have a relation between teta1 & teta2
teta2 = 5*teta1 (the mechanism can rotate in the first fix point)
i used to write this code for motion control but the when i run it the graphs are not correct (because they should be something linke sin or cos graph)
d(n) is a auxiliry vector for solving equations
please ask if you have further questions
this is the code :
clc,
close all,
clear all,
ax=0;
ay=0;
r1=12;
r2=7;
r3=9;
r4=5;
n=0;
for teta1=0:pi/180:2*pi
n=n+1;
D = r1*exp(i*teta1)-r2*exp(i*5*teta1);
tetad(n) = angle(D);
d(n) = abs(D);
landa(n)=acos((d(n)^2+(r3)^2-(r4)^2)/(2*d(n)*r3));
alfa(n)=acos((d(n)^2+(r4)^2-(r3)^2)/(2*d(n)*r4));
teta3(n)=landa(n)+tetad(n);
teta4(n)=(+pi-alfa(n)+tetad(n));
end
aa(n)=teta1*180/pi;
hh(n)=tetad(n)*180/pi;
bb(n)=landa(n)*180/pi;
cc(n)=alfa(n)*180/pi;
nn(n)=teta3(n)*180/pi;
dd(n)=5*teta1*180/pi;
ee(n)=teta4(n)*180/pi;
figure(1),plot(aa,hh),xlabel('teta1'),ylabel('tetad');
figure(2),plot(aa,d),xlabel('teta1'),ylabel('d');
figure(3),plot(aa,bb),xlabel('teta1'),ylabel('landa');
figure(4),plot(aa,cc),xlabel('teta1'),ylabel('alfa');
figure(5),plot(aa,nn),xlabel('teta1'),ylabel('teta3');
figure(6),plot(aa,dd),xlabel('teta1'),ylabel('5*teta1');
figure(7),plot(aa,ee),xlabel('teta1'),ylabel('teta4');
I have no idea what you are trying to solve here, but probably you want to move the end of your for-loop a few lines down, so the vectors you plot contain all values and not only the last one.