SCILAB undefined vairable error when using 'polarplot' - plot

I am getting the following error while running polarplot in scilab
// Program to plot using polarplot function
t= 0:.01:2*%pi;
polarplot(sin(t))
xtitle('Using polarplot'
result:
exec('D:\mangesh\SCILAB PROJ\sample\polarplot.sce', -1)
at line 13 of function polarplot ( C:\PROGRA~1\SCILAB~1.1\modules\graphics\macros\polarplot.sci line 25 )
at line 3 of executed file D:\mangesh\SCILAB PROJ\sample\polarplot.sce
Undefined variable: rho

The polarplot function requires at least 2 input arguments theta and rho,
In your example you forgot to give the evolution of the radius. for example:
polarplot(sin(t), ones(t))

As indicated by the other user as well the polarplot function requires at least two input vectors, like most of other plotting functions. It this case you probably want something like:
// Program to plot using polarplot function
t = 0:.01:2*%pi;
polarplot(t, sin(t));
xtitle('Using polarplot');
which yields:

Related

Solve the differential equation ⅆy/ⅆx+ⅇ^(-x) y=x^2 with y(x=0) = 0

tried solution
clear
clc
clf
function ydot=f(x)
ydot=x^2-(exp(-x)*y)
endfunction
x0=0 // initial x value
y0=0 // initial y value
x=0:.1:5 // x range
y=ode(y0,x0,x,f)
plot(x,y,'.-')
xtitle( 'Plot of Y vs X','X axis', 'Y axis')
// Display of the solution
sol='[x;y]'
disp('The solution is')
disp(sol)
getting error
in builtin exec( C:\Users\s b rakes\Desktop\SCI\2.sce line -1 )
Wrong number of input arguments.
ode: An error occurred in 'lsoda' subroutine.
I dont know why I am getting this error. Any body has solution or reason
you are missing one argument (y) in the rhs:
function ydot=f(x,y)
ydot=x^2-(exp(-x)*y)
endfunction
You should also remove the quotes there:
sol=[x;y]

Is there any ax.view_init(elev, azim) equivalent function in plots.jl?

I am using Plots for visualizing 3d-plots with Julia, and I am trying to change camera angle of my plot. In matplotlib in Python, I know that I can use ax.view_init(elev, azim) to change the camera angle, but on Plot.jl, I could not find solution to change the angle.
Is there any equivalent function with ax.view_init(elev, azim) in Python in Julia ?
Example of Plot
using Plots
plot()
for i in 1 : 5
a = rand(10); b= rand(10); c = rand(10);
plot!(a,b,c, seriestype=:scatter)
end
plot!()
As you can read in the manual you can use the camera keyword argument (aliases are: cam, cameras, view_angle, viewangle). This argument sets the view angle for 3D plots. Its value is required to be a tuple (azimuthal, elevation) and the default setting is (30, 30).

how to correctly pass a value to an included function?

I have 2 julia files, alpha.jl and beta.jl.
in alpha.jl, there are 2 functions:
der that returns a derivative using Zygote,
derPlot that plots the function as well as the derivative:
function der(f, x)
y = f'(x)
return y
end
function derPlt(der,z)
plot(f, aspect_ratio=:equal, label="f(x)")
g(f,x₀) = (x -> f(x₀) + f'(x₀)*(x-x₀))
plot!(g(f,x), label="dy",color="magenta")
xlims!(-z,z)
ylims!(-z,z)
end
everything comes out fine when i call these 2 functions in beta.jl, after including the files:
include("alpha.jl")
f(x)=-x^2+2
x = -1.3
derPlt(der(f, x), 6)
However, if i directly enter in a value for the function, the plotted derivative line doesnt update; i.e, if i enter 2.0 instead of passing in some variable named x,
derPlt(der(f, 2.0), 6)
no change is reflected on the plot. New to Julia, trying to understand and fix it.
I think it's because in your derPlt function, you call
plot!(g(f,x),...)
on x instead of the z argument. The problem is then that you define a x = -1.3, the value of which is used inside of derPlt, regardless of what z argument you feed it.
Maybe replace that line with
plot!(g(f,z),...)
and you should be fine.
Seeing as this is a follow up to a question I answered previously I thought I'd have to respond: Benoit is broadly speaking correct, you are running into a scoping issue here, but a few more changes are in order.
Note that your function signature is derPlot(der, z) but then:
You never actually use the der argument in your function body; and
You construct your tangent line as g(f,x₀) = (x -> f(x₀) + f'(x₀)*(x-x₀)) - note that there's no z in there, only an x
Now where does that x come from? In the absence of any x argument being passed to your function, Julia will look for it in the global scope (outside your function). Here, you define x = -1.3, and when you then call derPlt, that's the x that will be used to construct your tangent, irrespective of the z argument you're passing.
Here's a cleaned up and working version:
using Plots, Zygote
function derPlt(f,z)
plot(f, label="f(x)", aspect_ratio = :equal,
xlims = (-5,5), ylims = (-5,5))
g(f,x₀) = (z -> f(x₀) + f'(x₀)*(z-x₀))
plot!(i -> g(f, z)(i), label="dy",color="magenta")
end
f(x)=-x^2+2
derPlt(f, -1.5)
I would encourage you to read the relevant manual section on Scope of Variables to ensure you get an understanding of what's happening in your code - good luck!

problem with drawing graph of sum function in r

Let's take sample 'y' of length 100 from N(0,1) distribution and function g(x)=x^2+7.
I want to make a graph of function $h(x)=\sum_{i=1}^{100}g(x-y[i])$
So
y=rnorm(100,0,1)
g=function(x){x^2+7}
h=function(x){sum(g(x-y))}
And now expressions like
curve(h)
plot(h)
lines(h)
doesnt work, can You please help me how can i draw graph of function h?

How plot heart curve in scilab?

I have been looking in the forum and within the graphical functions of the program help, how to graph the following function:
x2=[-2:0.02:2]';x1=[-1:0.01:1]';
function val = Heart(x1, x2)
val=(1.2*x2-sqrt(abs(x1)))^2+x1^2-1;
endfunction
And I have not found anything to guide me.
I try to reproduce this maple plot:
Heart curve
an other solution is to solve the equation (1.2*x2-sqrt(abs(x1)))^2+x1^2-1 = c
for x2
The solution is quite easy
and one can found 2 branches
x2=(5/6)(sqrt(abs(x1))+sqrt(c+1-x1^2));
and
x2=(5/6)(sqrt(abs(x1))-sqrt(c+1-x1^2));
c=0;
x1=linspace(-1,1,200);
x1r=x1($:-1:1);
x2=(5/6)*[ (sqrt(abs(x1))+sqrt(c+1-x1^2)) (sqrt(abs(x1r))-sqrt(c+1- x1r^2))];
clf;plot([x1 x1r],x2);
Since your defining a 3D surface, you can use contour and contour2d: as said by luispauloml, you can pass the function directly as a parameter.
x1=[-1:0.01:1]
x2=[-2:0.02:2]
function val = Heart(x1, x2)
val=(1.2*x2-sqrt(abs(x1))).^2+x1.^2-1; // switched ^ to .^ to handle vectors
endfunction;
figure()
xlabel('x1')
ylabel('x2')
contour2d(x1,x2,Heart,[0 0]);
a=gca()
hline=a.children.children(1)
hline.foreground=color('red')
hline.thickness=2

Resources