clc
x = [1:1:10];
y1 = x;
y2 = 2*x;
y3 = 3*x;
plot2d(x,y1);
plot2d(x,y2);
plot2d(x,y3)
gca().children(1).children(1).thickness = 2
gca().children(2).children(1).thickness = 7
gca().children(3).children(1).thickness = 4
I am new from Matlab to Scilab
Could someone tell me, how to unterstand children?
What means
gca().children ?
gca().children.children ?
gca().children.children(1) ?
gca().children(1).children ?
How can we know which attribute belong to children ?
e.g gca().children(1).children(1).color = ... // not exist
I am very confused now.. Thanks in Advance
Let's schematize the nested graphical object by their children properties.
We have
figure (f)
- axes (a)
- compound1 (c1)
- polyline (p1)
- compound2 (c2)
- polyline (p2)
- compound3 (c3)
- polyline (p3)
Since gca is a function lets do a = gca() because gca().children will raise an error because scilab doesn't understand that you're trying to access to the fields of its return value.
gca() returns the handles to the axes of the current figure :a.
a.children returns the array of handles of all the children of theses axes. : c1, c2, c3
a.children.children returns the array of handles of all the children of the above objects: p1, p2, p3
a.children.children(1) returns the first children of c1, c2, c3 : p1
a.children(1).children returns all the children of the first children of the current axes (c1). Since there only one : p1
To access the value of your entities
Either go for a temp variable :
a = gca();
idcolor=a.children(1).children(1).foreground // gives the color of a.c1.p1
or use get
// idcolor is an array , with idcolor(i) the color of pi
idcolor = get(get(get(gca(),'children'),'children'),'foreground')
FYI
gce() command returns the handle of the last object created. With plot2d its a compound so we need to get its children.
you could rewrite your program as
clc
x = [1:1:10];
y1 = x;
y2 = 2*x;
y3 = 3*x;
plot2d(x,y1);
e1 = get(gce(),'children');
plot2d(x,y2);
e2 = get(gce(),'children');
plot2d(x,y3)
e3 = get(gce(),'children');
e1.thickness = 2
e2.thickness = 7
e3.thickness = 4
Related
I'm following this tutorial in order to try and do an FEA of a model.msh that I have to see how it would deform given different external forces in different places.
There they define the weak form as
a(u,v) = ∫( ε(v) ⊙ (σ∘ε(u)) )*dΩ
l(v) = 0
and they state "The linear form is simply l(v) = 0 since there are not external forces in this example."
As mentioned, I would like to analyse the different deformation that different external forces would cause on my model, but I can't seem to find anywhere an example of this. Could someone help me on defining this linear form for external forces different than 0?
Thanks.
Maybe this helps you out. It was written in a hurry, so please do not mind if you encounter spelling mistakes or other beauty issues :)
# define where the output shall go
output_Path ="Output/3_Gridap/1_Lin_FEA/FE_8"
mkpath(output_Path)
output_Name ="pde_6"
using Gridap
# please load the model that is shown in: https://gridap.github.io/Tutorials/dev/pages/t001_poisson/
model = DiscreteModelFromFile("Code/Meshes/Data/possion.json")
# just in case you want to see the model using paraview
writevtk(model,"$(output_Path)/md")
order = 1
reffe = ReferenceFE(lagrangian,VectorValue{3,Float64},order)
V0 = TestFESpace(model,reffe;
conformity=:H1,
# to see which elements belongs to "bottom" open the model which is saved through "writevtk(model,"$(output_Path)/md")"
dirichlet_tags=["bottom"],
# activate/deactivate the boundary conditions
dirichlet_masks=[
(true, true, true), # clamp the bottom
])
# define displacement
clamping(x) = VectorValue(0.0,0.0,0.0)
U = TrialFESpace(V0,[clamping])
const E = 7e+7
const ν = 0.33
const λ = (E*ν)/((1+ν)*(1-2*ν))
const μ = E/(2*(1+ν))
σ(ε) = λ*tr(ε)*one(ε) + 2*μ*ε
degree = 2*order
Ω = Triangulation(model)
dΩ = Measure(Ω,degree)
# Neumann boundary conditions
# here we define the surface on which we want an external force
Γ_Tr = BoundaryTriangulation(model,tags=["triangle"])
dΓ_Tr = Measure(Γ_Tr,degree)
# a force shall be applied on the y-direction
f_Tr(x) = VectorValue(0.0, 1e+6, 0.0)
# mass forces due to gravity, the value is set quite high, such that an impact can be seen
mass_Forces(x) = VectorValue(0.0, -1e+7, 0.0)
# Weak form
a(u,v) = ∫( ε(v) ⊙ (σ∘ε(u)) )*dΩ
l(v) = ∫( v ⋅ mass_Forces )* dΩ + ∫( v ⋅ f_Tr )* dΓ_Tr
op = AffineFEOperator(a,l,U,V0)
uh = solve(op)
writevtk(Ω,"$(output_Path)/$(output_Name)",
cellfields=[
"uh" => uh,
"epsi" => ε(uh),
"sigma" => σ∘ε(uh)])
So i found out how to create a vector2 in 2D using only one angle but now i need a vector3 using two or three angles
The code i used to get the 2D vector:
function V2ToForce(Angle,Force)
local Force = Force or 1
local X,Y = math.cos(Angle)*Force,math.sin(Angle)*Force
return X,Y
end
Any pseudocode would help.
Edit:
I found this formula but dosent work either
function Test(X,Y,Force)
local x = math.cos(X) * math.cos(Y);
local z = math.sin(X) * math.cos(Y);
local y = math.sin(Y);
return x*Force,y*Force,z*Force
end
Ty who commented got it to work, still has some bugs but nothing that a if statement can't solve.
Thats what i ended up with for anyone with the same problem
function Test1(X,Y,Force)
local X1 = math.cos(Y)*Force
local Y1 = (math.sin(Y)*math.sin(X))*Force
local Z1 = (-math.sin(Y)*math.cos(X))*Force
return X1,Y1,Z1
end
function Test2(X,Y,Force)
local X1 = math.cos(X) * math.cos(Y)
local Z1 = -math.sin(X) * math.cos(Y)
local Y1 = math.sin(Y)
return X*Force,Y*Force,Z1*Force
end
Sry for my bad english
I am trying to plot histograms of different columns of a dataframe in subplots.
plt_count = 1
for i = names(abalone)[2:end]
p[plt_count]=histogram(abalone[:,i])
plt_count += 1
end
plot(p, layout=(3,3), legend=false)
This is what I tried. But I can't come up with the right definition for the array p. How do I define p?
Improvements to the code will also be helpful.
If you don't care about the type stability, you can make Any type array.
ps = Array{Any}(nothing, 3)
ps[1] = plot([2,3,4])
ps[2] = plot([1,5])
ps[3] = plot([10,5,1,0])
#show typeof(ps)
plot(ps..., layout=(3,1))
If you want to create an array of Plot type specifically, one approach is to initialize an array with a dummy plot, then replace later.
ps = repeat([plot(1)], 3)
ps[1] = plot([2,3,4])
ps[2] = plot([1,5])
ps[3] = plot([10,5,1,0])
#show typeof(ps)
plot(ps..., layout=(3,1))
I would like to know how to overload a function in scilab. It doesn't seem to be as simple as in C++. For example,
function [A1,B1,np1]=pivota_parcial(A,B,n,k,np)
.......//this is just an example// the code doesn't really matter
endfunction
//has less input/output variables//operates differently
function [A1,np1]=pivota_parcial(A,n,k,np)
.......//this is just an example// the code doesn't really matter
endfunction
thanks
Beginner in scilab ....
You can accomplish something like that by combining varargin, varargout and argn() when you implement your function. Take a look at the following example:
function varargout = pivota_parcial(varargin)
[lhs,rhs] = argn();
//first check number of inputs or outputs
//lhs: left-hand side (number of outputs)
//rhs: right-hand side (number of inputs)
if rhs == 4 then
A = varargin(1); B = 0;
n = varargin(2); k = varargin(3);
np = varargin(4);
elseif rhs == 5 then
A = varargin(1); B = varargin(2);
n = varargin(3); k = varargin(4);
np = varargin(5);
else
error("Input error message");
end
//computation goes on and it may depend on (rhs) and (lhs)
//for the sake of running this code, let's just do:
A1 = A;
B1 = B;
np1 = n;
//output
varargout = list(A1,B1,np1);
endfunction
First, you use argn() to check how many arguments are passed to the function. Then, you rename them the way you need, doing A = varargin(1) and so on. Notice that B, which is not an input in the case of 4 inputs, is now set to a constant. Maybe you actually need a value for it anyways, maybe not.
After everything is said and done, you need to set your output, and here comes the part in which using only varargout may not satisfy your need. If you use the last line the way it is, varargout = list(A1,B1,np1), you can actually call the function with 0 and up to 3 outputs, but they will be provided in the same sequence as they appear in the list(), like this:
pivota_parcial(A,B,n,k,np);: will run and the first output A1 will be delivered, but it won't be stored in any variable.
[x] = pivota_parcial(A,B,n,k,np);: x will be A1.
[x,y] = pivota_parcial(A,B,n,k,np);: x will be A1 and y will be B1.
[x,y,z] = pivota_parcial(A,B,n,k,np);: x will be A1, y will be B1, z will be np1.
If you specifically need to change the order of the output, you'll need to do the same thing you did with your inputs: check the number of outputs and use that to define varargout for each case. Basically, you'll have to change the last line by something like the following:
if lhs == 2 then
varargout = list(A1,np1);
elseif lhs == 3 then
varargout = list(A1,B1,np1);
else
error("Output error message");
end
Note that even by doing this, the ability to call this functions with 0 and up to 2 or 3 outputs is retained.
I'm working on a game for iPhone which creates a path after your character as you move (movement is similar to snake but curvy in terms of steering). The way im doing it now is by just keeping all the vertices the player has been on in an array and then just draw a circle on every one of them each and every frame.
I wanna move on to using bezier curves instead. I've done a lot of reading about them and I understand them quite well, but im not really good with math. I've came to an understanding that i should use DeCasteljau's algorithm to split the curve at a specific t but i haven't found out just which formula to use and how to implement this in code.
So what I currently have is all the controlpoints for a curve at t=1. Now i just want to get all the controlpoints for t<1. Can somebody give me an easy to understand mathematical formula for this or an implementation (preferably in python or objective-c). Maybe there's even a object that you can use in iphone sdk to split curves already?
I managed to get it working, actually really simple math. Just calculate all the tangents for the bezier and you get the points.
Here's some python:
def sliceBezier(points, t):
x1, y1 = points[0]
x2, y2 = points[1]
x3, y3 = points[2]
x4, y4 = points[3]
x12 = (x2-x1)*t+x1
y12 = (y2-y1)*t+y1
x23 = (x3-x2)*t+x2
y23 = (y3-y2)*t+y2
x34 = (x4-x3)*t+x3
y34 = (y4-y3)*t+y3
x123 = (x23-x12)*t+x12
y123 = (y23-y12)*t+y12
x234 = (x34-x23)*t+x23
y234 = (y34-y23)*t+y23
x1234 = (x234-x123)*t+x123
y1234 = (y234-y123)*t+y123
return [(x1, y1), (x12, y12), (x123, y123), (x1234, y1234)]
To call it:
sliceBezier([(point1_x, point1_y),(controlpoint1_x, controlpoint1_y),(controlpoint2_x, controlpoint2_y),(point2_x, point2_y)], 0.23);
I implemented something like that, if you have a modern browser take a look here. It's implemented in javascript, and supports also higher order beziers.
Here is a solution using Apple's SIMD api. It is concise and returns both subdivided curves.
void SplitBezier(float t,
simd_float2 cv[4],
simd_float2 a[4],
simd_float2 b[4]) {
a[0] = cv[0];
b[3] = cv[3];
a[1] = simd_mix(cv[0], cv[1], t);
b[2] = simd_mix(cv[2], cv[3], t);
auto b12 = simd_mix(cv[1], cv[2], t);
a[2] = simd_mix(a[1], b12, t);
b[1] = simd_mix(b12, b[2], t);
a[3] = b[0] = simd_mix(a[2], b[1], t);
}