I am implementing an interpolating function using Octave, and I have the following in a Sublime text file:
function root = HermiteInterp(x, y, yp)
Q = zeros(2*length(x), 2*length(x));
disp(Q);
z = zeros(1, 2*length(x));
new_y = zeros(1, 2*length(x));
for i = 1:length(x)
z((2*i)-1) = x(i);
z(2*i) = x(i);
new_y((2*i)-1) = y(i);
new_y(2*i) = y(i);
y_prime(2*i) = yp(i);
end
y_transpose = transpose(new_y);
disp(y_transpose);
yp_transpose = transpose(y_prime);
append_to_Q = [y_transpose, Q];
disp('test1');
disp('test2');
Yet the function never makes it to the display statement. What's causing this?
Use arrow keys to scroll up and down the GUI.
Related
I'm trying to implement a function astronomical_constants but its giving me error
'name' undefined near line 2 column 10
function val = astronomical_constants(name)
switch name
case 'gravitational_constant'
val.name = 'gravitational_constant';
val.value = 6.667e-11;
val.uncertainity = 1e-12;
case 'equitorial_radius_earth'
val.name = 'equitorial_radius_earth';
val.value = 6*10^(20);
val.uncertainty = 1e-12;
endswitch
endfunction
a = astronomical_constants('gravitational_constant').value
I'm not able to understand how I can implement it correctly. Pls help
I am trying to create 2D heatmap from those two parameters:
diffQ = discharge(2:lgth) - discharge(1:lgth-1);
difft = time(2:lgth) - time(1:lgth-1);
My former colleague made code for just one parameter:
diff = discharge(2:lgth) - discharge(1:lgth-1);
bin = 1;
idiff = int32(diff);
mx = max(idiff);
mn = min(idiff);
msh = ones(((mx-mn)/bin)+2);
for i = 1:lgth-2
y = ((idiff(i)-mn)/bin)+1;
x = (((idiff(i+1)-mn)/bin)+1);
msh(x,y) = msh(x,y) + 1;
end
mshl = log(log(log(msh)+1)+1);
newplot();
surface(mshl,'EdgeColor','none');
colormap(heatMapA);
but I can't figure out how to change plot creating for my case.
Thanks a lot
Kozina
I know its a stupid question, but I have no idea how to solve it... Lets say I have something like:
x = fmincon(#myfun,x0,A,b,Aeq,beq,lb,ub,#mycon)
and later on :
function [c,ceq] = mycon(x)
c = ...
ceq = ...
How to pass additional variables into #mycon, such as
function [c,ceq] = mycon(x, variable)
if variable == 1
c = ...
ceq = ...
else
c = ...
ceq = ...
end
Thanks :)
You pass mycon as anonymous function:
x = fmincon(#myfun,x0,A,b,Aeq,beq,lb,ub,#(xx)mycon(xx,variable))
Note that variable is fixed at the moment the fmincon line is called.
So I am trying to take a bit of code that I use for interactive selection and identification. It works outside of a function but gives an error when I try to run it as a stand alone function.
my.identify <- function(data)
{
# allows you to create a polygon by clicking on map
region = locator(type = "o")
n = length(region$x)
p = Polygon(cbind(region$x, region$y)[c(1:n,1),])
ps = Polygons(list(p), ID="region")
sps = SpatialPolygons(list(ps))
# returns all data that overlaps new polygon sps
a=data[!is.na(overlay(data,sps)),] # here is the problem
return(a)
}
Basically it doesn't want to run the overlay function (function of the sp package). The error report is that I can't run the inherited functions??
Error in function (classes, fdef, mtable) : unable to find an
inherited method for function "overlay", for signature "matrix",
"SpatialPolygons"
Any ideas??? I'm new to function writing... so hopefully it will be easy.
This should work. overlay is deprecated and over should be used instead. The catch is that all objects should be Spatial*.
xy <- data.frame(x = runif(40, min = -200, max = 200),
y = runif(40, min = -200, max = 200))
plot(xy)
my.identify <- function(data) {
# allows you to create a polygon by clicking on map
region = locator(type = "o")
n = length(region$x)
p = Polygon(cbind(region$x, region$y)[c(1:n,1),])
ps = Polygons(list(p), ID="region")
sps = SpatialPolygons(list(ps))
# returns all data that overlaps new polygon sps
a=data[!is.na(over(SpatialPoints(data),sps)),]
return(a)
}
ident <- my.identify(xy)
points(ident, pch = 16)
You need to add a call to the package in your function:
my.identify <- function(data)
{
require('sp') ## Call to load the sp package for use in stand alone function
# allows you to create a polygon by clicking on map
region = locator(type = "o")
n = length(region$x)
p = Polygon(cbind(region$x, region$y)[c(1:n,1),])
ps = Polygons(list(p), ID="region")
sps = SpatialPolygons(list(ps))
# returns all data that overlaps new polygon sps
a=data[!is.na(overlay(data,sps)),]
return(a)
}
N00b here, having problems escaping strings. I used the QuotedStr() function - shouldn't that be enough.
Unfortunately, the string that I am trying to quote is rather messy, but I will post it here in case anyone wants to paste it into WinMerge or KDiff3, etc.
I am trying to store an entire Delphi form into the database, rather than into a .DFM file. It has only one field, a TEdit edit box.
The debugger shows the form as text as
'object Form1: TScriptForm'#$D#$A' Left = 0'#$D#$A' Top = 0'#$D#$A' Align = alClient'#$D#$A' BorderStyle = bsNone'#$D#$A' ClientHeight = 517'#$D#$A' ClientWidth = 993'#$D#$A' Color = clBtnFace'#$D#$A' Font.Charset = DEFAULT_CHARSET'#$D#$A' Font.Color = clWindowText'#$D#$A' Font.Height = -11'#$D#$A' Font.Name = 'MS Sans Serif''#$D#$A' Font.Style = []'#$D#$A' OldCreateOrder = False'#$D#$A' SaveProps.Strings = ('#$D#$A' 'Visible=False')'#$D#$A' PixelsPerInch = 96'#$D#$A' TextHeight = 13'#$D#$A' object Edit1: TEdit'#$D#$A' Left = 192'#$D#$A' Top = 64'#$D#$A' Width = 121'#$D#$A' Height = 21'#$D#$A' TabOrder = 8'#$D#$A' end'#$D#$A'end'#$D#$A
before calling QuotedStr() and
''object Form1: TScriptForm'#$D#$A' Left = 0'#$D#$A' Top = 0'#$D#$A' Align = alClient'#$D#$A' BorderStyle = bsNone'#$D#$A' ClientHeight = 517'#$D#$A' ClientWidth = 993'#$D#$A' Color = clBtnFace'#$D#$A' Font.Charset = DEFAULT_CHARSET'#$D#$A' Font.Color = clWindowText'#$D#$A' Font.Height = -11'#$D#$A' Font.Name = ''MS Sans Serif'''#$D#$A' Font.Style = []'#$D#$A' OldCreateOrder = False'#$D#$A' SaveProps.Strings = ('#$D#$A' ''Visible=False'')'#$D#$A' PixelsPerInch = 96'#$D#$A' TextHeight = 13'#$D#$A' object Edit1: TEdit'#$D#$A' Left = 192'#$D#$A' Top = 64'#$D#$A' Width = 121'#$D#$A' Height = 21'#$D#$A' TabOrder = 8'#$D#$A' end'#$D#$A'end'#$D#$A'''
afterwards.
The strange thing is that my complete command
'INSERT INTO designerFormDfm(designerFormDfmText) VALUES ("'object Form1: TScriptForm'#$D#$A' Left = 0'#$D#$A' Top = 0'#$D#$A' Align = alClient'#$D#$A' BorderStyle = bsNone'#$D#$A' ClientHeight = 517'#$D#$A' ClientWidth = 993'#$D#$A' Color = clBtnFace'#$D#$A' Font.Charset = DEFAULT_CHARSET'#$D#$A' Font.Color = clWindowText'#$D#$A' Font.Height = -11'#$D#$A' Font.Name = ''MS Sans Serif'''#$D#$A' Font.Style = []'#$D#$A' OldCreateOrder = False'#$D#$A' SaveProps.Strings = ('#$D#$A' ''Visible=False'')'#$D#$A' PixelsPerInch = 96'#$D#$A' TextHeight = 13'#$D#$A' object Edit1: TEdit'#$D#$A' Left = 192'#$D#$A' Top = 64'#$D#$A' Width = 121'#$D#$A' Height = 21'#$D#$A' TabOrder = 8'#$D#$A' end'#$D#$A'end'#$D#$A''");'
executes in a MySql console, but not from Delphi, where I pass that command as parameter command to a function which
ADOCommand.CommandText := command;
ADOCommand.CommandType := cmdText;
ADOCommand.Execute();
I can only assume that I am having problems escpaing sequences which contain single quotes (and QuotedStr() doesn't seem to escape backslahes(?!))
What am I doing that is obviously, glaringly wrong?
#mawg, the #da-soft suggestion is ok , the best way to interact with inserts and updates is using parameters.
check this sample
var
ADOCommand : TADOCommand;
begin
ADOCommand:=TADOCommand.Create(nil);
try
ADOCommand.Connection:=AdoConnection;
ADOCommand.Parameters.Clear;
ADOCommand.CommandText:='INSERT INTO designerFormDfm (designerFormDfmText) VALUES (:designerFormDfmText)';
ADOCommand.ParamCheck:=False;
ADOCommand.Parameters.ParamByName('designerFormDfmText').Value:= YourData;
ADOCommand.Execute;
finally
ADOCommand.Free;
end;
end;
The short answer - use the parameterized query !